Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sudhirbharti
Starting Member
16 Posts |
Posted - 2013-12-10 : 23:43:21
|
I want to update id column to be reset and incremented by 1 whenever the new siteid will come;Raw Table;ID SITEID PARSINGTYPE CONTROLLING SENSORID ALIAS ID20 95 3 0 1 Delivery Left 10 95 3 0 3 Delivery Right 20 95 4 0 4 Return Left 30 95 4 0 2 Return center 40 95 4 0 5 Return right 50 96 3 0 1 Delivery Left 60 96 3 0 2 Delivery Right 70 96 4 0 3 Return L 80 96 4 0 4 Return Center 90 96 4 0 5 Return R 10Desired tableID SITEID PARSINGTYPE CONTROLLING SENSORID ALIAS ID21 95 3 0 1 Delivery Left 12 95 3 0 2 Delivery Right 23 95 4 0 3 Return Left 34 95 4 0 4 Return center 45 95 4 0 5 Return right 51 96 3 0 1 Delivery Left 62 96 3 0 2 Delivery Right 73 96 4 0 3 Return L 84 96 4 0 4 Return Center 95 96 4 0 5 Return R 10 |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-12-11 : 09:04:01
|
[code];with cte as ( select id, row_number() over (partition by siteid orderby id2) as RN from YourTable) update cte set id = RN;[/code] |
|
|
|
|
|