VBA 中的 SQL 错误
我在 SQL (2005) 中有以下代码,它计算系统上的平均用户登录次数:
with
user_total as
(
select COUNT(distinct ID) as counter
FROM [dbo].[LOG]
where [LOG].DESCRIPTION='Login success.'
AND
Convert(datetime,convert(char(10),[LOG].CREATED_ON,101)) BETWEEN '2009-01- 01' AND '2009-12-31'
),
USER_avg as
(
select counter/365 as Avarage_Daily_Logins
from user_total
)
select *
from USER_avg
现在的问题是,当我将其放入 excel 中的 VBA 宏中以在 strSQL =“此处显示的查询”中的特定单元格中获取结果时“我在 excel 中遇到错误
关键字附近的系统语法不正确
值得一提的是,我不会在多行中破坏 VBA 中的代码..我将所有内容都放在一行中。
I have the following code in SQL (2005) which calculates the avarage user logins on a systm:
with
user_total as
(
select COUNT(distinct ID) as counter
FROM [dbo].[LOG]
where [LOG].DESCRIPTION='Login success.'
AND
Convert(datetime,convert(char(10),[LOG].CREATED_ON,101)) BETWEEN '2009-01- 01' AND '2009-12-31'
),
USER_avg as
(
select counter/365 as Avarage_Daily_Logins
from user_total
)
select *
from USER_avg
Now the problem is when i put this in a VBA macro in excel to get the result in a spcific cell in strSQL = "QUERY SHOWN ABOVE HERE" argument i get the error in excel
incorrect sysntax near the keyword with
Its worth mentioning that i dont break the code in VBA in multiple lines..i have it all in one line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
;WITH ...
CTE 的
WITH
用法必须在上一个语句之后有;
。为了确保这种情况,请添加前缀;
Use
;WITH ...
WITH
usage for a CTE must have;
after the previous statement. To ensure this is the cases, prefix with;
检查所有的间距,如果进一步出现错误,编译器可能会将其解释为
with
语句的问题。Check all of your spacings, if there is an error further down the compiler may interpret it as a problem with the
with
statement.