这是一个问题:从Person Table中选择BusinessEntityID,Title,First Name的第一个字母,MiddleName的第一个字母和Last Name(标签为Full Name),其中任何部分都没有NULL名称。
这就是我到目前为止:
Use AdventureWorks2008R2;
Select BusinessEntityID,SUBSTRING(Title,1,3)+' '+SUBSTRING(FirstName,1,1)+' '+
SUBSTRING(MiddleName,1,1)+' '+ LastName as 'Full Name'
From Person.Person
Where LastName IS NOT NULL;
但LastName列显示NULL值
答案 0 :(得分:1)
如果您连接在一起的任何列为NULL,则结果将为NULL。您还必须过滤掉Title,FirstName和MiddleName。
Use AdventureWorks2008R2;
SELECT BusinessEntityID,SUBSTRING(Title,1,3)+' '+SUBSTRING(FirstName,1,1)+' '+
SUBSTRING(MiddleName,1,1)+' '+ LastName as 'Full Name'
From Person.Person
Where LastName IS NOT NULL AND
Title IS NOT NULL AND
FirstName IS NOT NULL AND
MiddleName IS NOT NULL;
答案 1 :(得分:0)
您可以执行以下操作:
Use AdventureWorks2008R2;
Select BusinessEntityID,SUBSTRING(Title,1,3)+' '+SUBSTRING(FirstName,1,1)+' '+
SUBSTRING(MiddleName,1,1)+' '+ LastName as 'Full Name'
From Person.Person
Where LastName IS NOT NULL AND LastName != ''