我有两个数据库。 表1(学生)具有StudentID,EmployeeClass,StudentName字段。这里,EmployeeClass是varchar(5)。 表2(Employee)具有EmployeeID,EmployeeName,Description和EmployeeClass字段。 Employee Class是nvarchar(5)。
当我将Select Query编写为:
SELECT S.StudentID,
S.EmployeeClass,
S.StudentName
FROM Student AS S
LEFT OUTER JOIN Employee AS E
ON CAST(S.EmployeeClass AS VARCHAR(5)) = E.EmployeeID
WHERE E.Description = 'ABC'
所有值来自employee表显示为NULL?如何解决它
答案 0 :(得分:0)
我认为你的script.column中的连接条件是错误的。在这个脚本中,'EmployeeClass'指的是'EmployeeID'。
SELECT S.StudentID,
S.EmployeeClass,
S.StudentName
FROM Student AS S
LEFT JOIN Employee AS E
ON cast(S.EmployeeClass as varchar(5))= E.EmployeeClass
AND E.Description = 'ABC'