Please help me in creating an update query
- by Rajesh Rolen- DotNet Developer
I have got a table which contains 5 column and query requirements:
update row no 8 (or id=8) set its column 2, column 3's value
from id 9th column 2, column 3 value.
means all value of column 2, 3 should be shifted to column 2, 3 of upper row (start from row no 8) and value of last row's 2, 3 will be null
For example, with just 3 rows, the first row is untouched, the second to N-1th rows are shifted once, and the Nth row has nulls.
id math science sst hindi english
1 11 12 13 14 15
2 21 22 23 24 25
3 31 32 33 34 35
The result of query of id=2 should be:
id math science sst hindi english
1 11 12 13 14 15
2 31 32 23 24 25 //value of 3rd row (col 2,3) shifted to row 2
3 null null 33 34 35
This process should run for all rows whose id 2
Please help me to create this update query
I am using MS sqlserver 2005