Link to home
Start Free TrialLog in
Avatar of Mortarello
MortarelloFlag 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
Avatar of Aneesh
Aneesh
Flag of Canada image

update c
set surname = s.surname
from @copy c inner join @source s on s.id = c.id
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mortarello

ASKER

Hi  aneeshattingal,

Thanks  man, It works perfect !!!!