sql server - T-SQL Update Cell Based On Another Cell in Same Column for X Columns -


id | col1 | col2 | colx ------------------------  | 10   | 20  | v b  | 15   | 5   | w c  | 20   | 10  | x d  | 25   | 10  | y e  | 30   | 0   | z 

i value d/col1 (25) become value of cell plus value of b1/col1 (15) become 40

then value d/col2 (10) become value of cell plus value of b/col2 (5) become 15

similarly value d/colx (y) become value of cell plus value of b/col2 (w) become whatever w = y is

at end, i'd row b deleted (easy enough) produce like

id | col1 | col2 | colx ------------------------  | 10   | 20   | v c  | 20   | 10   | x d  | 40   | 15   | w+y e  | 30   | 0    | z 

there amount of columns , values, represented letters. got following work single column update)

  update [table]   set [col1]= (   select sum([col1]) [table] [id] in('b','d')   )   [id]='d' 

thanks!


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -