Saturday, 15 August 2015

sql server - UPDATE multiple Columns in SSMS/T-SQL: -



sql server - UPDATE multiple Columns in SSMS/T-SQL: -

i have next scenario.

update atable set c1 = 'xvalue' c2 = 'yvalue' update atable set c3 = 'mvalue' c4 = 'nvalue'

for performance tuning, can create them run under 1 update? better?

thank you

you can run 1 update using case

update atable set c1 = case when c2 = 'yvalue' 'xvalue' else c1 end, c3 = case when c4 = 'nvalue' 'mvalue' else c3 end c2 = 'yvalue' or c4 = 'nvalue'

sql sql-server sql-server-2008 tsql sql-update

No comments:

Post a Comment