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 |
scabral7
Yak Posting Veteran
57 Posts |
Posted - 2010-03-17 : 11:44:52
|
Hi,i have the following data:Account Seq123 1123 3123 4456 1456 1 456 2what i need to do is re-order the Seq column to remove any gaps or duplicates. I need the above to be like this:Account Seq123 1123 2123 3456 1456 2456 3Any ideas??thanksscott |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-17 : 11:50:19
|
[code]SELECT IDENTITY(int,1,1) AS ID,Account INTO #TempFROM TableSELECT r.Account,r.SeqFROM(SELECT t.Account,(SELECT COUNT(*) FROM #Temp WHERE Account=t.Account AND ID <t.ID) + 1 AS SeqFROM #Temp t)rORDER BY r.Account,r.Seq[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-03-17 : 12:02:06
|
Is this SQL 2000? (Its in the SQL 2000 forum ...) as there are easier ways in SQL 2005 onwards ... |
|
|
scabral7
Yak Posting Veteran
57 Posts |
Posted - 2010-03-17 : 13:52:13
|
yes, sql 2000 |
|
|
|
|
|