Getdate() as parameter store procedure

  • Hi,

    I have store procedure which need to execute with different parameters like

    beginning of month
    Last two months data
    ..

    create proc Results @date

    as
    Begin
    select col1,col2 from table1
    where date >= @Date

    End

    Now I need to pass parameters for this proc

    as

    Exec Results @Date = DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) - 2, 0) -- For last two months data?
    But I have error message Incorrect syntax ')'

    Could anyone have any suggestion how to pass Date parameters value using getdate() function

    Thanks

  • declare @Date datetime
    select @Date =DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) - 2, 0)
    Exec Results @Date

    You can't have expressions in the calling parameters.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply