| Author |
Topic |
|
dukey07
Starting Member
16 Posts |
Posted - 2004-08-12 : 15:56:59
|
| Hi all, having a brain freeze today, wondered if anyone can help on this one.Here is an example of a data set I have.RecID(Identity), AcctID, User1, 1234, Jim2, 2345, Bob3, 2345, Joe4, 3456, Phil5, 3456, Phil6, 3456, FredNow to adapt to some legacy code, I need it to look like the following.RecID, AcctID, User, SequenceID1, 1234, Jim, 12, 2345, Bob, 13, 2345, Joe, 14, 3456, Phil, 15, 3456, Phil, 26, 3456, Fred, 1I thought there was a way to do this using a join to a "Sequence" table (i.e. Table of integers 0-N)Any thoughts?Dukey |
|
|
Pat Phelan
Posting Yak Master
187 Posts |
Posted - 2004-08-12 : 16:00:40
|
I'd use something like:SELECT RecID, AcctID, User, (SELECT Count(*) FROM myTable AS b WHERE b.AcctID = a.AcctID AND b.RecID <= a.RecID) FROM myTable AS a -PatP |
 |
|
|
dukey07
Starting Member
16 Posts |
Posted - 2004-08-12 : 16:09:55
|
| Thanks a bunch PAt, that was quick. :)I think I am actually looking for this:SELECT RecID, AcctID, UserName, (SELECT Count(*) FROM #mytable AS b WHERE b.UserName = a.UserName AND b.RecID <= a.RecID) FROM #mytable AS abut, you put me on the right track!Thanks again,Dukey |
 |
|
|
dukey07
Starting Member
16 Posts |
Posted - 2004-08-12 : 16:24:01
|
Actually you need both for it to work.SELECTRecID, AcctID, UserName, (SELECT Count(*)FROM #mytable AS bWHERE b.UserName = a.UserNameAND b.AcctID= a.AcctIDAND b.RecID <= a.RecID)FROM #mytable AS a Dukey |
 |
|
|
|
|
|