Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
HI All,

Actual Table
EMPID SALARY Sequence
1 2000 NULL
1 2344 NULL
1 2345 NULL
2 4444 NULL
2 4434 NULL
2 3434 NULL
3 2344 NULL
3 3456 NULL

I need to update Sequence column result should be as follows
EMPID SALARY Sequence
1 2000 1
1 2344 2
1 2345 3
2 4444 1
2 4434 2
2 3434 3
3 2344 1
3 3456 2
Posted

1 solution

SQL
select t.rowno, t.EmpID, t.Salary into #temp from
(
   select row_number() over(partition by EMPID order by EmpID) as rowno, empID, Salary
   from ActualTable
) as t

-- to see the result you can do
select * from #temp

-- update your data
update ActualTable
 set Sequence = t.rowno
from #temp as t
inner join ActualTable as a on a.empID = t.empID and a.Salary = t.Salary

drop table #temp
 
Share this answer
 
Comments
partha_mspp 13-Mar-12 21:17pm    
Awesome
Herman<T>.Instance 14-Mar-12 4:38am    
it works for you?
partha_mspp 14-Mar-12 6:45am    
yes this is perfectly works for me Thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900