Monday, October 7, 2013

SQL 2005 and SQL 2000 implementation of ROW_NUMBER

-- SQL 2005 version

SELECT 
    RowNumber = ROW_NUMBER() OVER (ORDER BY c.LastName ASC)
    ,c.LastName
    ,c.FirstName
FROM SalesLT.Customer c


And the SQL 2000 version:
SELECT 
    RowNumber   = IDENTITY(INT,1,1)
    ,c.LastName
    ,c.FirstName
INTO #Customer_RowID
FROM SalesLT.Customer c
ORDER BY c.LastName ASC

No comments:

Post a Comment