[英]SQL Server error '80040e14' with syntax error nearby “ORDER”
I have been getting the SQL Server error '80040e14' saying Incorrect syntax near the keyword 'ORDER'. 我一直在收到SQL Server错误“ 80040e14”,在关键字“ ORDER”附近说语法不正确。 However, the line it is pointing is the next line to the line where there is the word "ORDER" Can someone point out the syntax mistake I did in the following sql code?
但是,它所指向的行是单词“ ORDER”所在行的下一行。有人可以指出我在以下sql代码中遇到的语法错误吗? ASP is the language I have been using for this project.
ASP是我在该项目中一直使用的语言。
SQL = " SELECT TS.ID, types"&_
" FROM tblTickets TS"&_
" WHERE TS.ID = "& Request("ticketid") &" ORDER BY dateof DESC"
SET RSticket = objConn.Execute(SQL) SET RSticket = objConn.Execute(SQL)
So,it points error in the last line whereas "ORDER" is in different line. 因此,它在最后一行中指出错误,而“ ORDER”在另一行中。
If Request("ticketid") returns a string value then you need to add single quotes around it: 如果Request(“ ticketid”)返回一个字符串值,则需要在其周围添加单引号:
SQL = " SELECT TS.ID, types"&_
" FROM tblTickets TS"&_
" WHERE TS.ID = '"& Request("ticketid") &"' ORDER BY dateof DESC"
the ORDER BY will fail, because dateof isnt a selected field ORDER BY将失败,因为dateof不是所选字段
try " WHERE TS.ID = "& Replace(Request("ticketid"),"'","''") &" ORDER BY 1 DESC"
尝试
" WHERE TS.ID = "& Replace(Request("ticketid"),"'","''") &" ORDER BY 1 DESC"
谢谢大家,我只是缺少&Request(“ ticketid”)的单引号引起来。现在它可以正常工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.