MS SQL Exception: Incorrect syntax near '@P0'

前端 未结 7 651
孤街浪徒
孤街浪徒 2020-12-03 16:36

I\'m querying a DB using MS SQL and for some reason I get the following error: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near \'@P0\' ev

相关标签:
7条回答
  • 2020-12-03 17:28

    It can also be caused by a syntax error in your SQL as was the case for me

    select * from drivel d where exists (select * from drivel where d.id = drivel.id and drivel.start_date < '2015-02-05' AND '2015-02-05' < drivel.end_date) OR exists (select * from drivel where d.id = drivel.id and drivel.start_date < '2015-02-05' AND '2015-02-05' < drivel.end_date) OR exists (select * from drivel where d.id = drivel.id and '2015-02-05' < drivel.start_date and drivel.end_date < '2015-02-05'
    

    gave the message

    com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P5'

    the problem was actually the balancing ')' missing at the end, namely, correct version is

    select * from drivel d where exists (select * from drivel where d.id = drivel.id and drivel.start_date < '2015-02-05' AND '2015-02-05' < drivel.end_date) OR exists (select * from drivel where d.id = drivel.id and drivel.start_date < '2015-02-05' AND '2015-02-05' < drivel.end_date) OR exists (select * from drivel where d.id = drivel.id and '2015-02-05' < drivel.start_date and drivel.end_date < '2015-02-05')
    
    0 讨论(0)
提交回复
热议问题