title: how to assign variable with exec string in sql?
body: <p>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...</p>
  
  <pre><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)
  </code></pre>
  
  <p>I would like to do something like...</p>
  
  <pre><code>set @sGeographyName  = exec (@sSQL)
  </code></pre>