Employee
表
编写一条SQL语句,该语句将改变下面提到的预先存在的存储过程以完成以下操作:
Emp_ID
Emp_ID
JOIN
确保结果显示如下:
Manager's Last Name
Employee's Last Name
Employees Hire Date
按经理的姓氏,最近的雇员和雇员的姓氏订购查询结果
这是预先存在的存储过程代码:
CREATE PROCEDURE dbo.sp_GetEmployeeNm
AS
SELECT
Last_Nm, Hire_Dt
FROM
dbo.Employee
WHERE
Mgr_ID IN (SELECT Emp_ID
FROM dbo.Employee
WHERE Emp_ID = 12345)
有没有人知道如何正确更改此存储过程?
这就是我的尝试:
ALTER PROCEDURE dbo.sp_GetEmployeeNm (@Emp_ID INT = 0)
AS
BEGIN
SELECT
m.Last_Nm AS Manager's Last Name,
e.Last_Nm AS Employee's Last Name,
e.Hire_Dt AS Employee's Hire Date
FROM
Employee e
INNER JOIN
Employee m ON e.Emp_ID = m.Mgr_ID
WHERE
e.Emp_ID = 12345
ORDER BY
(m.Last_Nm, e.Hire_Dt, e.Last_Nm) DESC
END
答案 0 :(得分:3)
ALTER PROCEDURE dbo.sp_GetEmployeeNm
@Emp_ID INT = 0
AS
BEGIN
SELECT
m.Last_Nm AS 'Manager''s Last Name',
e.Last_Nm AS 'Employee''s Last Name',
e.Hire_Dt AS 'Employee''s Hire Date'
FROM
Employee e
INNER JOIN
Employee m ON e.Emp_ID = m.Mgr_ID
WHERE
e.Emp_ID = @Emp_ID
ORDER BY
(m.Last_Nm, e.Hire_Dt, e.Last_Nm) DESC
END
GO
使用
EXEC dbo.sp_GetEmployeeNm 12345