Reputation: 1194
So I have a couple of temp tables I have created and am trying to move column contents from one table to another.
I populate #TempTable
with values I'm gleaning from another table using a particular set of logic. Once I'm done with the current section I want to move the contents of #TempTable.ColumnName
to another temp table (#Table1
) that is housing the collected results of the logic sets.
This is how I've done it:
SET @ExecStatement = 'Alter table #Table1 Add ' + @ColumnName +' varchar(250)';
EXEC (@ExecStatement)
set @ExecStatement = 'Update #Table1 set #Table1.'+@ColumnName+' = #TempTable.ColumnName ';
exec (@execStatement)
The error message appears on the second SET
statement.
Any help would be greatly appreciated.
Upvotes: 0
Views: 2098
Reputation: 40359
Nothing more than an invalid update statement -- SQL can't tell where to pull the data from. Try this as the second set
statement:
set @ExecStatement = 'Update #Table1 set ' + @ColumnName + ' = tt.TempConv from #Table1 ta inner join #TempTable tt on tt.Id = ta.Id
(replace "Id" with the proper column name)
Upvotes: 1