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
 General SQL Server Forums
 New to SQL Server Programming
 Update number in column

Author  Topic 

romeck
Starting Member

16 Posts

Posted - 2013-09-09 : 22:36:20
Hi i have table
id, series, seriesnr

and data
65557,AS,0
74443,AS,0

how to update table so seriesnr would be incremental , like
65557,AS,1
74443,AS,2
if i use
update x set seriesnr=select max(seriesnr) from x
then i got same seriesnr for all rows like max was calculated only one time on the begining not on each row update(why is that itseem so illogical)
65557,AS,1
74443,AS,1

THQ

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-09-10 : 00:47:14
update T
SET seriesnbr = RN
from (SELECT *, ROW_NUMBER() OVER(PARTITION BY series ORDER BY id) RN FROM TableName) T

--
Chandu
Go to Top of Page
   

- Advertisement -