Syntax error with ODBC drivers and DATEADD

JXWD 6 Reputation points
2022-04-14T22:34:10.553+00:00

I am using ODBC drivers and DATEADD I just cant get the syntax right

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
SELECT DATEADD (month, -2, #2020-10-10 00:00:00#) FROM TblCalibItems;

SQL Server Other
{count} vote

3 answers

Sort by: Most helpful
  1. Bert Zhou-msft 3,436 Reputation points
    2022-04-15T01:38:50.177+00:00

    Hi,@JXWD

    Welcome to Microsoft T-SQL Q&A Forum!

    First of all, confirm again whether you are a SQL Server database, because according to your description, the odbc connection function of the access database you use.
    in Tsql, the following from table is not needed, because you are just printing the first two months date,, and did not get any information from the table, I guess your table stores data in a date format, you can use parameter to store date data.

     SELECT DATEADD (month, -2, parameter) FROM TblCalibItems  
    

    Let's look at how to use the DateAdd function in MS Access:
    193199-image.png
    193302-image.png
    Best regards,
    Bert Zhou


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Jingyang Li 5,896 Reputation points Volunteer Moderator
    2022-04-15T03:24:46.367+00:00

    SELECT DATEADD ("m", -2, #2020-10-10 00:00:00#)

    0 comments No comments

  3. Dik Langan 0 Reputation points
    2024-02-07T17:02:09.7866667+00:00

    You missed the (single) quotes around the first parameter (month), and also that "month" is not a valid parameter for the ODBC version of the method, you have to use "m" instead so it should be:

    SELECT DATEADD ('m', -2, #2020-10-10 00:00:00#) FROM TblCalibItems;

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.