update nulls in column with another columns data

  • Seeking help with the following:

    column (1) (char) has data in some rows and remainder are null

    column (2) (int) has data and some rows are null

    would like to update table(1)

    set column (1) = column (2) only when column (2) is not null

    Thank you.

  • You already pretty much wrote the update

    update table(1)

    set column (1) = column (2) only when column (2) is not null

    in T-SQL is

    UPDATE table(1)

    SET column(1) = column(2) WHERE column(2) IS NOT NULL

  • You might want to also include "and Column1 is null" to the Where clause, so it only updates rows where Column1 is null and Column2 is not null.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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