February 6, 2013 at 10:51 am
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
February 6, 2013 at 11:13 am
what is the relationship between the tableA and tableB? Is it just the server name?
_Rafael - Br
February 6, 2013 at 11:34 am
Hi,
yes we have relationship with server name. we need to compare with server name and update the tableA.
If the server name is mathcing in both table the staus column is YES otherwise NO
February 6, 2013 at 11:58 am
There is something missing. Could you send us the complete table structures?
February 6, 2013 at 12:31 pm
It would be far more helpful if you posted ddl and sample. You can find out how to do that by reading the article at the first link in my signature for best practices when posting questions.
As a shot in the dark I think something like this should get you close.
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
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply