0

I am facing an error while running a SQL query.

The error I am receiving is:

(102, b"Incorrect syntax near '2020-01-31 00:00:00'.DB-Lib error message 102, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 102, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 102, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")

Since the query is lengthy, I am putting only part of the query where the error is being shown:

T1.submit_date < ts '2020-01-31 00:00:00'

If need be, I will edit and put the entire query.

Any help is appreciated.

Thank you.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
DHRUV KAUSHAL
  • 127
  • 10
  • what is ts here ? – Red Devil Feb 07 '20 at 08:05
  • This is SQL Server (Microsoft SQL, MS SQL) error message, not MySQL message. Compare one more time letter-by-letter: `MS SQL` and `MySQL`. – Akina Feb 07 '20 at 08:34
  • Hi Red. ts is timestamp, an ODBC literal escape sequence. More information here: https://stackoverflow.com/questions/15759458/what-is-ts-2013-04-02-000000 – DHRUV KAUSHAL Feb 07 '20 at 09:06
  • Hi Akina. It is MySQL that I am using in the backend. I am unclear on a thing. Are you suggesting that I should change the title of my question and the tags? I think the server is throwing an error because of something wrong in the query. – DHRUV KAUSHAL Feb 07 '20 at 09:07
  • If your employer told you to use [MySQL by Oracle Corporation](https://www.mysql.com/) you must have made something wrong because the error message you're getting comes from [SQL Server by Microsoft](https://www.microsoft.com/en-us/sql-server/sql-server-downloads). – Álvaro González Feb 07 '20 at 09:21
  • 1
    Oh really sorry guys. I am new to databases and didn't know that these two are two different technologies themselves. { insert embarrassed emoji here } – DHRUV KAUSHAL Feb 07 '20 at 10:50

1 Answers1

2

This is not the correct format for ODBC escape sequences. It should be wrapped in {}

where T1.submit_date < {ts '2020-01-31 00:00:00'}
Martin Smith
  • 438,706
  • 87
  • 741
  • 845
  • Upon changing the code to this, I get another error: _Keyerror at "ts '2020-01-31 00"_ – DHRUV KAUSHAL Feb 07 '20 at 11:40
  • That isn't a database error. Probably you need this https://stackoverflow.com/questions/5466451/how-can-i-print-literal-curly-brace-characters-in-python-string-and-also-use-fo – Martin Smith Feb 07 '20 at 11:54