In a stored procedure I get a record from a table and insert it into a temporary table #temp.
Then in this stored procedure I would like to set a value in a column of the #temp table as follows:
declare @VarName varchar(max)
set @VarName = 'Value is ' #temp.colname
There is an error on the last line. Of course I can get the value of #temp.varname into another variable, before setting @VarName. But I would like to know if it is possible to do it inline, without another variable name.
CodePudding user response:
I think this is what you mean, but it's pretty brittle in that it assumes you will only ever have one row in #temp.
DECLARE @VarName varchar(max) = (SELECT 'Value is ' colname FROM #temp);
- Example db<>fiddle