sopheak
asked on
SQL update question
I have a table with 2 columns. Column1 is given and sorted ascending, what i need to do is update column2 with corresponding values. Column 2 just should increment by one and reset to one when the value in column1 changes.
Col1 Col2
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
Thanks
sopheak
Col1 Col2
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
Thanks
sopheak
To be completely perfect, the cursor should have been declared like this:
Hope this helps ...
Hope this helps ...
declare Yveau cursor
for
select col1, col3
from #Y
order by col3 asc
--
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the row_number
Hope this helps ...
Open in new window