update query for isnull columns

  • Hi

    I have multiple columns around 10

    i am writing an update statement which doesn't update any of the rows

    update table

    set column11=isnull(columnA,0)+isnull(columnb,0)+...

    where quarter='Q3'

    also tried...

    update table

    set column11=SUM(COALESCE(column1,0) + COALESCE(column2,0))

    where quarter='Q3'

    both doesn't update column11. please help

  • do you get any results when you select rows using the same where clause?

  • Maybe some explanation what you are trying to do is needed.

    Preferably in the form of table DDL, sample data and desired output.

    See the link in my signature about asking questions.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • batgirl (10/27/2014)


    do you get any results when you select rows using the same where clause?

    The rephrase the above question, what do you get when you run the query below?

    SELECT * FROM table WHERE quarter = 'Q3'



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Somehow it worked after deleting the data and imported the new data to the table and re-executed the below query.

    update table

    set column11=isnull(columnA,0)+isnull(columnb,0)+...

    where quarter='Q3'

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

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