AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 How to Include Simple Row Number to a SQL Query : SQL Server 2005
Posted by Moderator1 on  3/14/2008 8:34:55 PM 3969 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

Featured Resources:
No Nonsense XML Web Development With PHP - Free 146 Page Preview!
Learn how to put XML to practical use on your Website.
Simply JavaScript - Free 150 Page Preview!
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
100% Free Subscription until Stock lost.View complete list.
Sponsored by