Thursday, August 18, 2011

RowNumber() function in sqlserver database

This function is applicable from sqlserver2005 version onwards.In order to find the in between customer out of 10,000 names,we can use the below query in sqlserver database.

For me i am using Customer Tables which contains 1,00000 names.The following query helps me to find 100 to 200 customers
information as follows:

WITH CustomerDetails AS
(
SELECT Email,
ROW_NUMBER() OVER (ORDER BY Cust_ID desc) AS 'RowNumber'
FROM Customer where cust_type=2
)
SELECT *
FROM CustomerDetails
WHERE RowNumber BETWEEN 100 AND 200;