Translate

Friday, September 13, 2024

TSQL - Update Using A List of Values

I needed to update around 800 addresses from a list of addresses in a spreadsheet. I saved the spreadsheet as csv and then formated the csv fields into a list of values. Then I wrote an SQL select statement that took the list of values and made it into a subquery that I could join on the address table.

This is the finale SQL with just a subset of the values:

update aglA 
set aglA.telephone = lh.phone
from address aglA 
join (select * from (values('100000','1 707 822 4226'),('100010','1 707 826 9681'),('100030','1 707 445 8248'))as x( res_id, phone))lh on lh.res_id = aglA.res_id 

No comments:

Post a Comment

Thank you for commenting!