这是我的 CTE - 它导致错误。帮我找出错误
CREATE TABLE [dbo].[myEmpTab](
[EMPNO] [int] NULL,
[ENAME] [varchar](10) NULL,
[JOB] [varchar](20) NULL,
[MGR] [int] NULL,
[HIREDATE] [datetime] NULL,
[SAL] [int] NULL
) ON [PRIMARY]
;
WITH MyCTE AS
(
SELECT EMPNO, EName, Null as MGR, NULL as ManagerName
FROM myEmpTab
WHERE MGR IS NULL
UNION ALL
SELECT EMPNO, EName, MGR, MyCTE.EName
FROM myEmpTab
INNER JOIN MyCTE ON myEmpTab.MGR = MyCTE.EMPNO
WHERE myEmpTab.MGR IS NOT NULL
)
SELECT * FROM MyCTE
当我执行 sql 时,我会收到类似的错误
Msg 209, Level 16, State 1, Line 8
Ambiguous column name 'EMPNO'.
Msg 209, Level 16, State 1, Line 8
Ambiguous column name 'EName'.
Msg 209, Level 16, State 1, Line 8
Ambiguous column name 'MGR'.
我无法捕捉到错误。所以请任何人有很多,并帮助我解决它。谢谢。