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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update ref_no with seq numbers

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2009-07-15 : 11:47:18
Hi i need to work out a way for adding in a seq_no for a references number. I can have multiple references number

what i need is like the below so the ref & seq_no are unique.

ref_no seq_no
1 1
1 2
2 1
2 2
2 3
3 1
4 1
4 2
5 1
5 2

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-15 : 12:50:06
[code]SELECT ref_no,ROW_NUMBER() OVER (PARTITION BY ref_no ORDER BY ref_no) AS seq_no FROM Table[/code]
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2009-07-16 : 04:47:19
HEY CAN I USE ROW_NUMBER() IN A UPDATE STATEMENT ?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-16 : 05:05:01
UPDATE f
SET seq_no = recid
FROM (
SELEC seq_no, row_number() Over (partition by ref_no order by ref_no) as recid
) AS f


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -