Reputation: 5566
For each first and last name I would just like to combine and update them into the fullname column in the same "names" table.
This should happen for every row in the table. The columns are Id, FirstName, LastName and FullName.
Any help would be appreciated
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
Upvotes: 2
Views: 9980
Reputation: 28751
This UPDATES FullName Colum that are blank or have NULL values.
UPDATE Names
SET FullName = ISNULL(FirstName + ' ','') + ISNULL(LastName,'')
WHERE ISNULL(FullName,'') = ''
EDIT
UPDATE Names
SET FullName = FirstName + ' ' + LastName
WHERE ISNULL(FullName,'') = '' AND ISNULL(FirstName,'') <> '' AND ISNULL(LastName,'') <> ''
Upvotes: 4