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 |
deanglen
Yak Posting Veteran
65 Posts |
Posted - 2013-10-25 : 05:35:17
|
HiI have a table with 13,000 rows, in one column called Prioirty each row has a value of 1.Is it possible to use SQL to replace all of these '1' values with a sequential list. Example 1,2,3,4,5,6,7....all the way to 13,000? |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-10-25 : 07:56:16
|
Declare @Tem table (Id int,Name char(2))Insert @TemSelect 1,'a'union all Select 1,'b'union all Select 1,'c'union all Select 1,'d'union all Select 1,'e'Declare @Tem1 Table (Name char(2),Rn int)Insert @Tem1Select Name,Rn=Row_Number() Over(Order By Name) From @TemUpdate tSet Id=RnFrom @Tem tinner join @Tem1 as t1on t.Name = t1.NameSelect * From @Temveeranjaneyulu |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-25 : 08:32:07
|
Why an unnecessary join? keep it simpleUPDATE tSET ID = SeqFROM ( SELECT ROW_NUMBER() OVER (ORDER BY Name) AS Seq,ID FROM Table )t ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-10-28 : 05:48:59
|
Another simple method isdeclare @i intset @i=-1update your_table set Prioirty =@i+1, @i=@i+1 MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|