Get row number for a sql table
Today I had an interesting dilema – needed to associate a row number with each row in a record set that I needed to retrieve from a sql table. In other words, if I have 15 rows in the record set, I needed to be able to get the record id of the 14th row. Searching through google I stumbled on ROW_NUMBER() function in sql server. The function is supported for sql server 2005 and up. That’s all it took to get the job done:
SELECT MyRandomTableID, Name, ROW_NUMBER() OVER (ORDER BY Name) AS RowNumber
FROM MyRandomTable
Categories
Archives
Software Quotes
??Software Blogs
February 2012 M T W T F S S « Nov 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29





