Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Adding Sequence number
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vack
Aged Yak Warrior

USA
530 Posts

Posted - 10/01/2012 :  10:57:42  Show Profile  Reply with Quote


Have a table HDR with columns

ord_no   line_seq_no  comm_cd
  123        1          Z
  123        2          Y
  123        3          X
  222        1          C
  222        2          B
  222        3          A

I would like to create a view and add an extra column that will re sequence the lines by comm_cd. So I would get the following result.

ord_no   line_seq_no  comm_cd  New_Seq
  123        1          Z         3
  123        2          Y         2
  123        3          X         1
  222        1          C         3
  222        2          B         2
  222        3          A         1


visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 10/01/2012 :  11:04:27  Show Profile  Reply with Quote


SELECT ROW_NUMBER() OVER (PARTITION BY ord_no ORDER BY comm_cd) AS New_Seq,*
FROM yourtable


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next 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