Tuesday, October 6, 2009

Create Serial Number Column using SQL Server

There is a common requirement to show records with serial number in Grid. The common scenario is, we can generate serial number using variable which is incremented each time. The another approach is to generate this column in SQL itself. Yes you can do that..! Here is a Query for that.
SELECT ROW_NUMBER() OVER (ORDER BY ColumnName1) As SrNo, ColumnName1, ColumnName2 FROM TableName

No comments:

Post a Comment