我有一个简单的存储过程,它返回记录:

Select empID, EmpFirstName, EmpLastName from EMPLOYEES

返回的结果是:
    EmpID         EmpFirstName       EmpLastName
    -----         ------------       -----------
   30152          John               Smith
   30114          Tom                Jones
   56332          Steve              Williams
   85442          Paul               Johnson

我需要的是:
 RecID       EmpID         EmpFirstName       EmpLastName
 -----       -----         ------------       -----------
 1      30152          John               Smith
 2      30114          Tom                Jones
 3      56332          Steve              Williams
 4      85442          Paul               Johnson

如何获取recordID列?

谢谢

最佳答案

可能想使用Row_Number:

Select ROW_NUMBER() OVER(ORDER BY empID) AS RecId,
       empID,
       EmpFirstName,
       EmpLastName
from EMPLOYEES

除非RecId中实际上有一个EMPLOYEES列,在这种情况下就是这样:
Select RecId,
       empID,
       EmpFirstName,
       EmpLastName
from EMPLOYEES

关于sql - 在我的SQL选择查询中获取recordID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7003822/

10-10 05:26