Tuesday, November 4, 2008

Serial Number in Sql Server Select statement

During one of my task in daily routine i come to problem where i need addition column in the select statement of the sql server. And after the research on the net i have found a link which gave solution to my problem. Vmaceda has give the solution of how to get the serial number in select statement, both for sql server 2000 and also for sql server 2005, just for my friends i write the select statements which i have used and for there easyness.

For Sql server 2005
SELECT Column1 ,Column2 = ROW_NUMBER() OVER(ORDER BY Column1),
FROM tblTableName

For Sql Server 2000
SELECT ( SELECT SUM(1) FROM tblTableName WHERE Column1 <= tableName.Column1) AS 'Serial Number'
FROM tblTableName tableName

2 comments:

Adnan Aslam said...

Nice Work buddy...
Please keep it up...

Tasleem said...

hmm good, i have used ROW_NUMBER() function for paging on sql server side as well,but on 2005 not 2000.