99problems
99problems

Reputation: 71

Incorrect syntax near '1' sql

I am trying to understand why I am getting the following error when running the query:

Incorrect syntax near '1'

Select  * 
From    _datatable 
WHERE   Dateadded BETWEEN DATE_SUB(GETDATE(), INTERVAL 1 MONTH) AND GETDATE()

Upvotes: 2

Views: 9649

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415725

I see mixed syntax from two different database engines here: SQL Server and MySQL.

Here's the SQL Server way:

SELECT * 
FROM _datatable 
WHERE Dateadded BETWEEN DATEADD(month, -1, current_timestamp) AND current_timestamp

And in MySQL:

SELECT * 
FROM _datatable 
WHERE Dateadded BETWEEN DATE_ADD(current_timestamp, INTERVAL - 1 MONTH) AND current_timestamp

Upvotes: 3

Related Questions