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.
Advertisement
Answer
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).