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
 Resequence field

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2014-07-02 : 15:45:22
I have data below that is not validating against an index I want to put on the table.
Index is on the four fields below.

Looking for a script that will re sequence the line_no field by inv_no


ord_no line_no item_no inv_no
123 1 ABC 777
123 1 ABC 778
123 1 ABC 778

After running script data should look like

ord_no line_no item_no inv_no
123 1 ABC 777
123 1 ABC 778
123 2 ABC 778




update oelinhst
set line_no = ????

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-02 : 15:59:31
select ord_no, row_number() over(partition by inv_no order by ord_no) as line_no, item_no, inv_no
from yourtable

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -