Friday, June 25, 2010

How to show running serial no. in SQL SERVER Select Statement


I am working on a project where the SQL is generated at runtime depending on users selection and i am show the records from database in a Gridview control.
I am to show Running Serial Nos. as Serial No. column as the first column in the grid.

The solution to this requirement is to to genarate SR.No column in SQL as follows

SELECT ROW_NUMBER() OVER (ORDER BY ColumnName1) As Sr_No, ColumnName1, ColumnName2 FROM TableName


No comments: