i have a sql query:
select id, name from table order by name
result looks like this:
52 arnold
33 berta
34 chris
47 dori
The answer depends on which version of SQL you are using.
If you are using MSSQL 2005 you can use the the new analytical function ROW_NUMBER () which generates the sequential number in order which we define in order by clause. The syntax of ROW_NUMBER () function is:
ROW_NUMBER () OVER (ORDER BY )
or
ROW_NUMBER () OVER (PARTITION BY )
If you are using an older version of SQL Server you can create a temp table with an identity column and select the results from that.