I would like to assign a variable with what is returned from and "exec (string)" but am struggling with syntax. Below is some working code...
declare @iGeographyLevel int = 2
declare @iGeographyLevelID int = 64
declare @sGeographyName varchar(30)
declare @sSQL nvarchar(max)
set @sSQL = '
select Name
from GeographyLevel'+ cast(@iGeographyLevel as varchar(5))+'
where GeographyLevel'+ cast(@iGeographyLevel as varchar(5)) + 'ID = '+ cast(@iGeographyLevelID as varchar(5))
exec (@sSQL)
I would like to do something like...
set @sGeographyName = exec (@sSQL)