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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update statement with condition

Author  Topic 

nasty84
Starting Member

6 Posts

Posted - 2010-01-13 : 15:22:21
For e.g i have the following data
ID Source Segment Groupid Sequence SegSeq SegGroupseq
1 1 A1 100 1 null null
2 1 A2 100 2 null null
3 1 A3 100 3 null null
4 2 B1 100 4 null null
5 1 A2 100 5 null null
6 1 A3 100 6 null null
7 1 B1 100 7 null null
8 1 A1 200 1 null null
-
-
-
-
-


i need to update the SegSeq and SegGroupseq

i.e, the data should look like this...

ID Source Segment Groupid Sequence SegSeq SegGroupseq
1 1 A1 100 1 1 1
2 1 A2 100 2 2 1
3 1 A3 100 3 3 1
4 2 B1 100 4 1 1
5 1 A2 100 5 3 2
6 1 A3 100 6 3 3
7 2 B1 100 7 1 2
8 1 A1 200 1 1 1
-
-
-
-
-

For a groupID, different segments can occur.For a groupID, if a new segment occurs we have to increment the SegSeq. But, if the segment occurs again in the same groupID,
we need to update it with last maximum number of that groupID segment's SegSeq number.And incrment the SegGroupSeq. If a new source starts with different segmenr and for
the same group SegSeq and starts with 1.
Is there any way without using Cursors.
Thanks for your help and time..
   

- Advertisement -