Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update multiple fields??

Author  Topic 

phrankbooth
Posting Yak Master

162 Posts

Posted - 2009-01-27 : 11:56:55
Hi,

I have this table:
Col1|Col2
AAAA|1111
BBBB|2222
CCCC|3333
DDDD|4444

I want to Update Col2 of rows BBBB and CCCC.
So that my result is:
Col1|Col2
AAAA|1111
BBBB|0000
CCCC|9999
DDDD|4444

What would the single Update statement be for this?

Thanks!


--PhB

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-27 : 11:59:26
just use

UPDATE table
SET Col2=CASE WHEN Col1 = 'BBBB' THEN '0000' ELSE '9999' END
WHERE Col1 IN ('BBBB','CCCC')
Go to Top of Page

phrankbooth
Posting Yak Master

162 Posts

Posted - 2009-01-27 : 12:17:29
Thanks for the quick reply!

--PhB
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-27 : 12:20:39
welcome
Go to Top of Page
   

- Advertisement -