silent_hunter
silent_hunter

Reputation: 2508

Update concatenating strings in temporary table

I want to create temporary table in SQL Server and after that I what to update from other table.First table should contain data from concatenation first name and last name into one column MyFullName.

You can see code below:

# Create table
CREATE TABLE #MyNames (MyFullName NVARCHAR(100))

# Update table #MyNames 
SELECT CONCAT(c.FirstName,e.LastName) AS MyFullName
FROM dbo.Customer c
CROSS JOIN  dbo.Employee e 
UPDATE #MyNames 
SET #MyNames.MyFullName = MyFullName
GO

Below you can see output from this code:

enter image description here

I try to update with this code and code give good result, but problem is arise when I try to see only updated table which is totally empty.

SELECT *
from #MyNames

So can anybody help me how to fix this error and make update properly?

enter image description here

Upvotes: 0

Views: 423

Answers (1)

M.Ali
M.Ali

Reputation: 69504

Or you can simply do

-- Add a white space between first name and last name, to make it more readble.
SELECT CONCAT(c.FirstName, ' ',e.LastName) AS MyFullName 
   INTO #MyNames 

FROM dbo.Customer c
CROSS JOIN  dbo.Employee e 

Upvotes: 1

Related Questions