ROW_NUMBER (Transact-SQL)

The ROW_NUMBER() function returns the number of a row within a result set starting with 1 for the first row. The ROW_NUMBER() function does not execute until after a WHERE clause is used to select the subset of data.
The following example returns the row number for each contact in AdventureWorks based on the LastName and [...]