I'm sure this is really easy but I just can't figure it out:
I have a stored procedure where I am building a sql statement dynamically, the sql statement returns a single value and I want to assign that returned value to a local variable for future use in the procedure:
declare @myValue varchar(10)
declare @sql varchar(500)
Set @sql = 'SELECT col1 FROM ' + @tableName + ' WHERE x=y'
set @myValue = result of above sql statement
How is this acheived?