In Sql Server, if I want to update a column based on the next row data from another column in 1 query how is this possible ?
e.g. :
I have a data like this : I want to populate ColumnC with ColumnB next row data.
Can I write a dynamic query that would be used to populate ColumnC otherwise I have to use Cursor.
ColumnA | ColumnB | ColumnC
---------------------------------------------
X 10 20
X 20 30
X 30 40
X 40 NULL
Y 25 40
Y 40 NULL
Z 35 39
Z 39 45
Z 45 NULL
e.g. :
I have a data like this : I want to populate ColumnC with ColumnB next row data.
Can I write a dynamic query that would be used to populate ColumnC otherwise I have to use Cursor.
ColumnA | ColumnB | ColumnC
---------------------------------------------
X 10 20
X 20 30
X 30 40
X 40 NULL
Y 25 40
Y 40 NULL
Z 35 39
Z 39 45
Z 45 NULL