为什么我的错误?或者是否可以进行这样的查询?
select Employee.EmployeeID, Employee.LastName + ', ' + Employee.FirstName + ' ' + Employee.MiddleName as EmployeeFullName
From Employee
Where EmployeeFullName = 'someFullName'
列名称无效' EmployeeFullName'。
答案 0 :(得分:0)
可能是因为任何field
(lastname, firstname,middlename
)可能是null
而发生错误
试试这个
select
Employee.EmployeeID,
isnull(Employee.LastName,'') + ', ' + isnull(Employee.FirstName,'') + ' ' + isnull(Employee.MiddleName,'') as EmployeeFullName
From Employee
Where AuthorFullName = 'someFullName'
编辑1)
你的条件错误,这就是你得到的原因(无效的列名'AuthorFullName'。)这个错误。
编辑2)
select
Employee.EmployeeID,
isnull(Employee.LastName,'') + ', ' + isnull(Employee.FirstName,'') + ' ' + isnull(Employee.MiddleName,'') as EmployeeFullName
From Employee
Where isnull(Employee.LastName,'') + ', ' + isnull(Employee.FirstName,'') + ' ' + isnull(Employee.MiddleName,'') = 'someFullName'
答案 1 :(得分:0)
SELECT FullName FROM
(
SELECT
FullName = LastName + ', ' + FirstName + ' ' + MiddleName
FROM Employee
) sub
WHERE sub.FullName = 'someFullName'