November 8, 2014 at 1:46 pm
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
November 8, 2014 at 10:29 pm
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
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy