"Date is Incompatible with int" 使用子查询时

"Date is Incompatible with int" while using sub-query

我还是 SQL 的新手。我正在尝试显示出生日期在 1955 年之前的所有“人员”记录,使用子查询提取该年之前的所有员工生日:

SELECT 
    PP.FirstName, PP.LastName
FROM 
    Person.Person PP
INNER JOIN
    HumanResources.Employee HE ON PP.BusinessEntityID = HE.BusinessEntityID
WHERE 
    BirthDate = (SELECT YEAR(BirthDate)
                 FROM HumanResources.Employee
                 WHERE YEAR(BirthDate) < 1955)

我已经 运行 分别尝试了主查询和子查询,它们都有效。但是一起使用它们,我得到了那个错误:

Msg 206, Level 16, State 2, Line 2
Operand type clash: date is incompatible with int

我错过了什么?谢谢,如果你决定提供帮助。

您可能还打算比较 WHERE 子句中 BirthDate 的年份,而不是日期本身:

SELECT PP.FirstName, PP.LastName
FROM Person.Person PP
INNER JOIN HumanResources.Employee HE
    ON PP.BusinessEntityID = HE.BusinessEntityID
WHERE YEAR(BirthDate) IN (SELECT YEAR(BirthDate)         -- change is here
                          FROM HumanResources.Employee
                          WHERE YEAR(BirthDate) < 1955);