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.
| Author |
Topic |
|
awalsql
Starting Member
11 Posts |
Posted - 2008-06-11 : 18:34:34
|
| SOURCE TABLEID________COMMENT123_______I am joe123_______I am programmer124_______I am Wang124_______I am programmer124_______I like cricketDESTINATION TABLEID_____SEQ______COMMENT123_____1_______I am joe123_____2_______I am programmer124_____1_______I am wang124_____2_______I am programmer124_____3_______I like cricketcan somebody please advise the easiest way to do this in sql 2000? |
|
|
awalsql
Starting Member
11 Posts |
Posted - 2008-06-11 : 22:48:38
|
| Guys, this problem is solved. Below is the code I found.ThanksCreateTable SRC(noint identity(1,1) ,idint,commentvarchar(20))InsertInto SRC Values (123,'I am Joe')InsertInto SRC Values (123,' I am programmer')InsertInto SRC Values (124,'I am Wang')InsertInto SRC Values (124,' I am programmer')InsertInto SRC Values (124,'I like Criket') CreateTable DEST(idint,seqint,commentvarchar(20))Declare@seq intDeclare@id intDeclare@comment varchar(20)Declare@seqmax intDeclare@nomax intDeclare@no intSet@id = 123Set@seq = 1While(@id<=124)BeginSelect @seqmax = count(*) from SRC Where id = @idSelect @no = min(no) from SRC Where id = @idSelect @nomax =max(no) from SRC Where id = @idSelect @id =id,@comment=comment From SRC Where id = @id and no =@noWhile(@no<=@nomax)BeginInsert Into DESTSelect @id,@seq,comment From SRC Where id = @id and no =@noSet @no = @no + 1Set @seq =@seq + 1EndSet @seq = 1Set @id =@id +1EndSelect* From DEST |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-12 : 00:54:20
|
| Do you have any other column in your table with unique values? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-12 : 09:52:31
|
| You can also doselect id, (select count(*) from src where id=t.id and no<=t.no) as no, commentfrom src t order by 1,2MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|