title: Obtain output parameter values from dynamic SQL
body: <pre><code>declare @var varchar(max),@course varchar(max)
  set @var='ABC'
  set @Query=''
  set @Query='  
  select @course=PARAM from TABLE where PARAM='''+@var+''''
  print @Query
  exec (@Query)
  </code></pre>
  
  <p>Since the above query returns an error as </p>
  
  <blockquote>
    <p>Must declare the scalar variable "@course"</p>
  </blockquote>
  
  <p>The query here is the alternative I am following right now to make that query successful.</p>
  
  <pre><code>declare @var varchar(max),@course varchar(max),@Query varchar(max)
  Create table #temp(param1 varchar(max))
  set @var='ABC'
  set @Query=''
  set @Query='insert #temp(param1)
  select PARAM from TABLE where PARAM='''+@var+''''
  print @Query
  exec (@Query)
  select @course=param1 from #temp
  drop table #temp
  </code></pre>
  
  <p>Is there any other better alternative to this other than the solution I have mentioned above?</p>