locked
sql script variables and datediff function RRS feed

  • Question

  • Hello

    I try to create a simple script to retrieve an information from a table

    the data should Datetime column which provide this data 2020-04-29 14:42:21.003

    so, I have declared a variable date and I set the function getdate() to get the current date

    declare @date date
    set @date = getdate()

    then, I have use SELECT to find the month. I have used the clause  WHERE MONTH(@date) < (@date - 1) 

    the idea is that I want to find the date before or maybe the day before, so I have tried this option:

    --here I used the current day and I want to show the month before

    declare @date date
    set @date = getdate()


    SELECT[DateTime  
      FROM [Archiver].[dbo].[Event11]

      WHERE MONTH(@date) < (@date - 1) 

    I got this error 

    Msg 206, Level 16, State 2, Line 10
    Operand type clash: date is incompatible with int

    Could you please help me this this request?

    Regards


    Wednesday, April 29, 2020 7:39 PM