对于每个名字和姓氏,我只想将它们组合在一起并将它们更新为同名"名称"中的全名列。表。
这应该发生在表格中的每一行。列是Id,FirstName,LastName和FullName。
任何帮助将不胜感激
update Names n
set n.FullName = (
select CONCAT(FirstName,' ',LastName)
from Names a
where n.Id = a.Id
)
where n.FullName is null
and n.FirstName is not null and n.LastName is not null
答案 0 :(得分:4)
此更新FullName Colum为空或具有NULL值。
UPDATE Names
SET FullName = ISNULL(FirstName + ' ','') + ISNULL(LastName,'')
WHERE ISNULL(FullName,'') = ''
修改强>
UPDATE Names
SET FullName = FirstName + ' ' + LastName
WHERE ISNULL(FullName,'') = '' AND ISNULL(FirstName,'') <> '' AND ISNULL(LastName,'') <> ''