Update statement

  • Hi All,

    I am passing three date variables in the stored procedure. Depending on whichever variable has value in it, it will be assigned to the Testdate column of the testable. Only one variable will have value others will be null

    Create procedure test

    (

    @TestDate datetime =NULL,

    @Testdate2 dateTime=NULL,

    @TestDate3 datetime=NULL

    )

    AS

    Update testable

    Set TestDate = @TestDate

    Its just that depending on whatever variable has value in it that will be assigned to the column TestDate.

    Any help will be appreciated.

  • Use COALESCE()

    ...

    Set TestDate = COALESCE( @TestDate, @TestDate2, @TestDate3)

    ...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • anjaliagarwal5 (5/10/2016)


    Hi All,

    I am passing three date variables in the stored procedure. Depending on whichever variable has value in it, it will be assigned to the Testdate column of the testable. Only one variable will have value others will be null

    Create procedure test

    (

    @TestDate datetime =NULL,

    @Testdate2 dateTime=NULL,

    @TestDate3 datetime=NULL

    )

    AS

    Update testable

    Set TestDate = @TestDate

    Its just that depending on whatever variable has value in it that will be assigned to the column TestDate.

    Any help will be appreciated.

    I really hope you have a WHERE clause on your actual UPDATE statement.

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

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