Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

conditional update Expand / Collapse
Author
Message
Posted Thursday, March 21, 2013 8:58 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, February 24, 2014 3:59 AM
Points: 82, Visits: 45
I want to update a column a in table A based on column b1 in table B. If table B has a value b1_1 for column b1, a should be updated as b1_1. If b1_1 is not present then a should be updated with b1_2 and so forth.

Is there a way to do this in one update query?

Post #1433840
Posted Thursday, March 21, 2013 10:23 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:49 PM
Points: 12,946, Visits: 12,355
chandni.247 (3/21/2013)
I want to update a column a in table A based on column b1 in table B. If table B has a value b1_1 for column b1, a should be updated as b1_1. If b1_1 is not present then a should be updated with b1_2 and so forth.

Is there a way to do this in one update query?



Yes.

If you want more specific help you need to provide some more details. Please a take a few minutes and read the article found at the first link in my signature for best practices when posting questions.

Once you post ddl, sample data and desired output this should be pretty quick and easy.


_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1433896
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse