列组合参数

时间:2013-08-12 11:41:16

标签: tsql sql-server-2008-r2 sqlparameters

为什么我的错误?或者是否可以进行这样的查询?

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

列名称无效' EmployeeFullName'。

2 个答案:

答案 0 :(得分:0)

可能是因为任何fieldlastname, 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'