-2

为什么我有这个错误?或者是否有可能有这样的查询?

select Employee.EmployeeID, Employee.LastName + ', ' + Employee.FirstName + ' ' + Employee.MiddleName as EmployeeFullName
From Employee
Where EmployeeFullName = 'someFullName' 

列名“EmployeeFullName”无效。

4

2 回答 2

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)

您的 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'
于 2013-08-12T11:44:37.133 回答
0
SELECT FullName FROM 
( 
    SELECT 
        FullName = LastName + ', ' + FirstName + ' ' + MiddleName
        FROM Employee  
) sub 
WHERE sub.FullName = 'someFullName'
于 2013-08-12T12:03:20.043 回答