have a temptable as follows
1. id empid triggerstatus
1 2881 null
2 2881 null
3 2881 null
4 2882 null
i need a sql query which will update the triggerstatus dynamically
to triggerstatus+1 if the empid is repected twice,trice,etc.
my result should look as
id empid triggerstatus
1 2881 1
2 2881 2
3 2881 3
4 2882 1
If you have SQL Server 2005+ you can use a CTE and ROW_NUMBER Windowing function:
You may want to add a
WHEREclause if there are some records that you do not want to updatetriggerStatusfor.