Thursday, June 11, 2009

How to Generate Running Serial Number Column using SQL Server

We often need to show records in a grid with Record No/Serial No as 1 column in the gridview control. records with serial number in Grid.
The solution for it is using ROW_NUMBER() as a part of the SQL for gridivew control.

use it like this

SELECT ROW_NUMBER() OVER (ORDER BY SomeColumnName) As SerialNo, Column2, Column2 FROM TableName

you can also use where clause to generate serial numbers for selected/filtered records

No comments: