2

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
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sealer_05
  • 5,346
  • 8
  • 35
  • 53
  • You could use Update from Select like its explained here: http://stackoverflow.com/questions/2334712/update-from-select-using-sql-server – dacaballero Nov 18 '16 at 05:47

1 Answers1

4

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,'') <> ''
Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133