为什么我有这个错误?或者是否有可能有这样的查询?
select Employee.EmployeeID, Employee.LastName + ', ' + Employee.FirstName + ' ' + Employee.MiddleName as EmployeeFullName
From Employee
Where EmployeeFullName = 'someFullName'
列名“EmployeeFullName”无效。
为什么我有这个错误?或者是否有可能有这样的查询?
select Employee.EmployeeID, Employee.LastName + ', ' + Employee.FirstName + ' ' + Employee.MiddleName as EmployeeFullName
From Employee
Where EmployeeFullName = 'someFullName'
列名“EmployeeFullName”无效。
可能发生错误,因为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)
您的 where 条件错误,这就是您收到 (Invalid column name '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'
SELECT FullName FROM
(
SELECT
FullName = LastName + ', ' + FirstName + ' ' + MiddleName
FROM Employee
) sub
WHERE sub.FullName = 'someFullName'