vba odbc 3704 mysql_VBA / ADODB运行时错误:3704

bd96500e110b49cbb3cd949968f18be7.png

The following VBA subroutine will run most queries just fine. (ie: SELECT * FROM DUAL)

Sub DisplayQuery(QueryString As String)

Dim rs As New ADODB.Recordset

Dim connStr As String

connStr = _

"Provider=MSDAORA.1;" _

& "User ID=abc;Password=123;" _

& "Data Source=xxx/xxx;"

out QueryString

rs.Open QueryString, connStr, adOpenStatic, adLockOptimistic

Range("DataTable").Clear

Cells(1, 1).CopyFromRecordset rs

End Sub

However, when I run the query below, the following error message immediately pops up: Run-time error '3704':Operation is not allowed when the object is closed.

with all_hours as

( select to_date('2009-11-03 05:00 PM','yyyy-mm-dd hh:mi PM') + numtodsinterval(level-1,'hour') hour

from dual

connect by level <= 4 /*hours*/

)

select h.hour

, count(case when h.hour = trunc(s.sampled_on,'hh24') then 1 end) sampled

, count(case when h.hour = trunc(s.received_on,'hh24') then 1 end) received

, count(case when h.hour = trunc(s.completed_on,'hh24') then 1 end) completed

, count(case when h.hour = trunc(s.authorized_on,'hh24') then 1 end) authorized

from all_hours h cross join sample s

group by h.hour

Why?

解决方案

I just restructured my query (link), so that I could put it into a view. I then created a connection in Excel to view name.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值