AspdotnetCodes.com
US and UK Data Centers – DiscountASP.NET
 
Articles Subscribe for our Articles Updates
Books
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
 How to Include Simple Row Number to a SQL Query : SQL Server 2005
Posted by Moderator1 on  3/14/2008 8:34:55 PM 501 Views
 
SQL Server 2005 provides a new function called Row_Number() which helps to generate row numbers in the query.

The syntax is

ROW_NUMBER() OVER (ORDER BY your_primary_column_name ASC) AS ROWID, * FROM your_table_name

Sample Query for a Customer Table is

SELECT ROW_NUMBER() OVER (ORDER BY CusCode ASC) AS ROWID, * FROM Customers Where DeptNo='HR'

Happy Queries!!

Post New Tips/Tricks View all Tips/Tricks

Sponsored by