Home > Back-end >  Error You have an error in your SQL syntax
Error You have an error in your SQL syntax

Time:07-18

When I do the following request I get the message :

(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>= DATEADD(MONTH, -3, GETDATE())' at line 1").

The request is :

'SELECT creationdate ' \
       'FROM panel' \
       'WHERE creationdate >= DATEADD(MONTH, -3, GETDATE())' \

This request works when I remove the WHERE line, however when I replace it (as a test) by 'LIMIT 10' , I get the same error...

What I would want to get the last 3 months of records.

Some help would be welcome please, thank you.

CodePudding user response:

You're missing a space after panel, so MySQL sees "FROM panelWHERE", which certainly is a syntax error:

>>> 'SELECT creationdate ' \
...        'FROM panel' \
...        'WHERE creationdate >= DATEADD(MONTH, -3, GETDATE())'
'SELECT creationdate FROM panelWHERE creationdate >= DATEADD(MONTH, -3, GETDATE())'
#                              ^ There!

Turn

'FROM panel' \

to

'FROM panel ' \

(like you had done with 'SELECT creationdate ' already).

  • Related