TSQL Statement Help Please

  • Hi I have an update statement which performs UPDATES to column when the WHERE condone = 'Yes' ..

    UPDATE dbo.Table1

    SET colA = (SELECT col1 FROM Table2 WHERE col10 = 'A')

    ,SET colB = (SELECT col1 FROM Table2 WHERE col10 = 'A')

    WHERE colC = 'Yes'

    However, should the WHERE be equal to anything else apart from 'Yes' I would want the two columns to be SET to NULL.

    I you could please help me out with the syntax.

    Thank you

  • UPDATE dbo.Table1

    SET colA = CASE ColC WHEN 'Yes' THEN (SELECT col1 FROM Table2 WHERE col10 = 'A') ELSE NULL END

    ,SET colB = CASE ColC WHEN 'Yes' THEN (SELECT col1 FROM Table2 WHERE col10 = 'A') ELSE NULL END

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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