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
 Adding Sequence number
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vack
Constraint Violating Yak Guru

USA
497 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
52323 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  
 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.09 seconds. Powered By: Snitz Forums 2000