[删除了公司机密信息或图形]
我的数据库中有这种结构。我需要建立一个员工姓名列表,然后是他们的部门和办公室的名称。到目前为止,我已经来到了这个查询:
ALTER PROCEDURE FilterEmpList
@empName nvarchar(250) = null,
@empDepID int = null,
@empOfficeID int = null,
@empPosID int = null
AS
BEGIN
SELECT
E.emp_id AS 'emp_id',
E.emp_name AS 'emp_name',
(SELECT pos_name FROM Positions WHERE pos_id=EP.pos_id) AS 'pos_name',
(SELECT dep_name FROM Departments WHERE dep_id=OS.dep_id) AS 'dep_name',
(SELECT office_name FROM Offices WHERE office_id=OS.office_id) AS 'office_name'
FROM
Org_Structure OS INNER JOIN (Emp_Positions EP INNER JOIN Employees E ON EP.emp_id=E.emp_id) ON OS.chain_id=EP.chain_id
WHERE
(E.emp_name LIKE '%'+@empName+'%' OR @empName IS NULL)
AND
(OS.dep_id = @empDepID OR @empDepID IS NULL)
AND
(OS.office_id = @empOfficeID OR @empOfficeID IS NULL)
AND
(EP.pos_id = @empPosID OR @empPosID IS NULL)
END
当我以这种方式执行 exec FilterEmpList时,会发生错误:Invalid object name 'EP'。