I ran the following query in SQL
declare @h nvarchar(max)
declare @i int
set @i =1
declare @two nvarchar(max)
select @h = 'set @two = (select word from #LocalTempTable where Idcolumn =' + cast(@i as nvarchar(max)) +')'
exec(@h)
print @two
I got the following error
Msg 137, Level 15, State 1, Line 1
Must declare the scalar variable "@two".
Why is this happening?