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 2000 Forums
 SQL Server Development (2000)
 Aggregated Row sequence numbering

Author  Topic 

xega
Starting Member

10 Posts

Posted - 2002-08-22 : 20:24:07
Guys,

I think I have a rather simple problem, but I could not get it solved. Anyone out there to help me out.

OK, here is the problem. Lets say I have a temp table #temp that look like the on below:


COLUMN_1 SEQUENCE_ID
-------- -----------
A NULL
A NULL
B NULL
B NULL
B NULL
C NULL
C NULL
C NULL
C NULL



What I want is the #temp table to look like this:


COLUMN_1 SEQUENCE_ID
-------- -----------
A 1
A 2
B 1 <- The sequence_id needs to be reset
B 2 to 1 when the row value in COLUMN_1
B 3 changes
C 1
C 2
C 3
C 4


Seing from the above, the sequencing for SEQUENCE_ID is by COLUMN_1 aggregation.

The real catch is I do not want to use while loops or cursors, I want to update using single line update like the one below:


[I got this code off the SQL Team website]
[http://www.sqlteam.com/item.asp?ItemID=765]
[Creating a Sequential Record Number field ]
[graz on 9/25/2000 in UPDATE ]

------------------------------------------------------------

declare @intCounter int
set @intCounter = 0
update Yaks
SET @intCounter = YakSequenceNumber = @intCounter + 1

------------------------------------------------------------


However the code above only sequences in the following manner:

COLUMN_1 SEQUENCE_ID
-------- -----------
A 1
A 2
B 3
B 4
B 5
C 6
C 7
C 8
C 9




So I need to to tweak the statement to number the sequence by
aggregation. I think I've done it some time back, but I could not recall it. So help would be really appreciated.

Thanks in advance and regard
Xega


Whenever I start to think, my brain freezes therefore I think I'm cool...

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-08-22 : 20:27:08
Do not double post:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=19066

Go to Top of Page
   

- Advertisement -