Possible Duplicate:
Add row number to this T-SQL query
Im using sql server 2008.
When I type: select * from Employee. The result like this:
EmpID | EmpName | Salary
-------------------------------------
DB1608 | David | 100000
JT2607 | John | 150000
AM1707 | Ann | 140000
ML1211 | Mary | 125000
But I want the result like this:
No | EmpID | EmpName | Salary
--------------------------------------------------
1 | DB1608 | David | 100000
2 | JT2607 | John | 150000
3 | AM1707 | Ann | 140000
4 | ML1211 | Mary | 125000
The column "No" is the auto increment number, and NOT the identity field in this table.
How can I do this?
Using ROW_NUMBER()
(documentation)
SELECT ROW_NUMBER() OVER (ORDER BY EmpID ASC) AS No,
EmpID, EmpName, Salary
FROM Employee
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With