SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update number in column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

romeck
Starting Member

16 Posts

Posted - 09/09/2013 :  22:36:20  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 09/10/2013 :  00:47:14  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000