简体   繁体   中英

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'. 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? ASP is the language I have been using for this project.

SQL = " SELECT TS.ID, types"&_
      " FROM tblTickets TS"&_
      " WHERE TS.ID = "& Request("ticketid") &" ORDER BY dateof DESC"

SET RSticket = objConn.Execute(SQL)

So,it points error in the last line whereas "ORDER" is in different line.

If Request("ticketid") returns a string value then you need to add single quotes around it:

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

try " WHERE TS.ID = "& Replace(Request("ticketid"),"'","''") &" ORDER BY 1 DESC"

谢谢大家,我只是缺少&Request(“ ticketid”)的单引号引起来。现在它可以正常工作了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM