title: Dynamic SQL Result INTO #Temp Table
body: <p>I have to Execute a dynamic SQL <code>SELECT</code> Query And put Results into a <code>#TempTable</code>.</p>
  
  <pre><code>DECLARE @StateId CHAR(3)='StateID';  
  DECLARE @DeptId CHAR(15)='DeptID';  
  DECLARE @Query VARCHAR(MAX)='Select Columns With Joins Passed From Front End'  
  DECLARE @Where VARCHAR(500);  
  DECLARE @FinalQuery VARCHAR(MAX)='';  
  SET @Where='Some Where Condition';  
  SET @FinalQuery='SELECT '+@Query+' '+@Where+''  
  EXEC(@FinalQuery) -- Want To INSERT THIS Result IN SOME `#TempTable` 
                    -- SO that I can perform Some Operations On `#TempTable`
  </code></pre>
  
  <p>ALSO No Of columns returned From Dynamic SQL <code>SELECT</code> Are Dynamic.</p>
  
  <p>Thanks,</p>