TSQL Basic- Update only if existing value is NULL

  • In a proc with update table command , which updates 5 columns in a table ,

    how do i make only 2 columns(NewCredit) on those 5 to get updated only if the existing value of that file dis NULL.

    In short: update only if existing value is NULL

    Thanks

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

  • I think you need this?

    UPDATE {TABLE}

    SET {COLUMN1}=CASE WHEN {COLUMN1} IS NULL THEN {something something}

    END

    Repeat case statement for all applicable columns

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The only difference between impossible and possible is time...and a little help from my friends.

  • UPDATE dbo.Table SET Col = CASE WHEN Col IS NULL THEN 'some new value' ELSE Col END WHERE --filter ony required rows

  • Thanks Guys

    I was'nt sure of the ELSE Case

    This answered

    🙂

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

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

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