Avatar of Mortarello
Mortarello
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Updating table from another table using memory tables

Hello Guys,

I'm trying to uptade a memory table from another memory tabble like the code bellow.
but I'm geting the error saying (Must declare the scalar variable "@source".)

Is there any way how to do this using memory table ?

---------------------------------------

 declare @source table (id int, name varchar(30), surname varchar(30))
 declare @copy table (id int, name varchar(30), surname varchar(30))
 
 insert into @source (id,name,surname) values(1,'michel','mortarello')
 insert into @source (id,name,surname) values(2,'michel','mortarello')

 
 insert into @copy (id,name) values(1,'michel')
 insert into @copy (id,name) values(2,'michel')
 

 update @copy
      set surname = @source.surname
      from @copy inner join @source on @source.id = @copy.id
 
 select * from @copy
 


Many thanks guys
Microsoft SQL Server 2008Microsoft SQL Server

Avatar of undefined
Last Comment
Mortarello

8/22/2022 - Mon
Aneesh

update c
set surname = s.surname
from @copy c inner join @source s on s.id = c.id
ASKER CERTIFIED SOLUTION
Aneesh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mortarello

ASKER
Hi  aneeshattingal,

Thanks  man, It works perfect !!!!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck