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.
Author |
Topic |
aswindba1
Yak Posting Veteran
62 Posts |
Posted - 2013-02-06 : 12:50:21
|
I need to update statusB column in tableA by comparing server name. If the server name in tableA is matching with Server name in tableB then the staus column in tableA should be Yes else NoAS IStable A statusB TableB ----------------- ---------Server1 Server1server2 server8 server3 server6server4 server4TO BETable A StatusB--------------------Server1 Yesserver2 Noserver3 NoServer4 yes |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-06 : 13:08:15
|
Do you have two tables or just one? If you have two tables (and if the columns are what I am guessing they are), then may be this is what you need:UPDATE a SET [statusB] = CASE WHEN b.ServerName IS NULL THEN 'No' ELSE 'Yes' ENDFROM TableA a LEFT JOIN TableB b ON a.Servername = b.ServerName; If it is all in one table and you are replacing the second column with Yes or No, thenUPDATE TableA SET TableB = CASE WHEN statusB = TableB THEN 'Yes' ELSE 'No' END; |
|
|
aswindba1
Yak Posting Veteran
62 Posts |
Posted - 2013-02-06 : 13:39:08
|
Thank you very much for your prompt reply... |
|
|
|
|
|