当它在ACCESS中显示正确的结果时,为什么我的sql命令不能在asp上运行?

时间:2013-12-05 06:45:49

标签: sql ms-access asp-classic ms-access-2007

现在我得到了这个论坛的帮助,我有sql命令可以在ACCESS中产生正确的结果。但是,当我把它用于ASP时,错误就像这样说..

Microsoft JET Database Engine error '80040e14'

The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

我做错了什么?我的asp代码是......。

Dim rsBill
set rsBill = Server.CreateObject("ADODB.Recordset")
rsBill.ActiveConnection = Conn_string<br>
rsBill.Source ="select sum(tbt.bill_total) as bill_total ,iif(sum_vat_total is null, 0, sum_vat_total) as vat_total, iif(sum_vat_total is null, 0, sum_vat_total) + sum(bill_total) as sum_of_all, month(showndate) as month from tbl_bill_total tbt left join (select sum(vat_total) as sum_vat_total , month(showndate) as month from tbl_vat_bill_total where if_paid = true and year(showndate) = 2013 group by month(showndate)) tvt on tvt.month = month(tbt.showndate) where year(showndate) = 2013 group by  month(showndate) , sum_vat_total"
rsBill.CursorType = 0
rsBill.CursorLocation = 3
rsBill.LockType = 3
rsBill.Open()
rsBill.PageSize = 20

我已经尝试了好几天才能找出错误但却无法得到它。

1 个答案:

答案 0 :(得分:3)

SELECT语句包含 month 作为别名(在两个地方)...

month(showndate) as month

由于存在具有相同名称的函数, month 可能是db引擎抱怨的保留字。如果要保留该别名,请将其括在方括号中。

month(showndate) as [month]

您报告在Access会话中运行的查询没有错误。在这种情况下,查询从DAO运行。但是从ADO运行时它失败了,因为ADO似乎对保留字不太宽容。