• 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 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/