Feb 8, 2014

Assign Unique ID within groups of records

GroupBy
 
select orderId,
       row_number() over(PARTITION BY orderId ORDER BY orderId) as lineNum
from Order


SELECT *,row_number() over(PARTITION BY CustNum,SoHDHeThong ORDER BY CustNum,SoHDHeThong) FROM order

 Not Group By
SELECT ROW_NUMBER() OVER (ORDER BY SomeField) AS Row, *
FROM SomeTable

0 comments:

Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib