SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help in Update statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aswindba1
Yak Posting Veteran

USA
62 Posts

Posted - 02/06/2013 :  12:50:21  Show Profile  Reply with Quote
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 No

AS IS

table A statusB TableB
----------------- ---------
Server1 Server1
server2 server8
server3 server6
server4 server4


TO BE

Table A StatusB
--------------------
Server1 Yes
server2 No
server3 No
Server4 yes

James K
Flowing Fount of Yak Knowledge

3744 Posts

Posted - 02/06/2013 :  13:08:15  Show Profile  Reply with Quote
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' END
FROM 
	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, then
UPDATE TableA SET
	TableB = CASE WHEN statusB = TableB THEN 'Yes' ELSE 'No' END;
Go to Top of Page

aswindba1
Yak Posting Veteran

USA
62 Posts

Posted - 02/06/2013 :  13:39:08  Show Profile  Reply with Quote
Thank you very much for your prompt reply...
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000