Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Have a table HDR with columnsord_no line_seq_no comm_cd 123 1 Z 123 2 Y 123 3 X 222 1 C 222 2 B 222 3 AI 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
52326 Posts
Posted - 2012-10-01 : 11:04:27
SELECT ROW_NUMBER() OVER (PARTITION BY ord_no ORDER BY comm_cd) AS New_Seq,*FROM yourtable
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/