I have some aggregated data :
name asd colA ColB ColC X Y
-----------------------------------------------
...
George PJ Sp P B 14.8 56
George PJ Sp P C 11.4 43
...
-----------------------------------------------
And a local result table
declare @result table(
Name nvarchar(255),
SP_E_A int null,
SP_E_B int null,
SP_E_C int null,
SP_E_D int null,
SP_E_viso decimal(5,1) null,
...
--LOTS MORE COLUMN GOES AFTER
...
)
It has lots of columns
What I'm trying to do is :
generate an update statement dynamically and execute it
Example:
UPDATE TABLE @table SET SP_P_B = 56
So I wrote this
open cursor for *that result set*
declare @sql varchar(255) = 'UPDATE @table SET '+@colA+'_'+@colB+'_'+@colC+'='+CONVERT(varchar,@Y);
exec (@sql)
Error I'm getting
Must declare the table variable "@table".
Looks like exec starts another session where @result table doesn't exist.
How can I work around it ?