title: How to execute this SQL Query
body: <p>I am having following scenario </p>
  
  <pre><code>Drop Table #Temp
  Create Table #Temp(name1 text, name2 text)
  
  Insert INTO #Temp Values ('test','test')
  Insert INTO #Temp Values ('test','test')
  
  Insert Into #Temp1 Select * From 
  (
  ;With CTE as (
   Select * from #Temp
   ) 
   select * from CTE
  )
  </code></pre>
  
  <p>I know we can't use <code>CTE</code> as subquery .. but for hard time I don't know exact syntax of subquery since it is being provided by other system. </p>
  
  <p>just image this </p>
  
  <pre><code> Insert Into #Temp1 Select * From 
      (
       "Query Provided by Other System"
      )
  </code></pre>
  
  <p>So I don't have any control on subquery ("<strong>Query Provided by Other System</strong>").. And I have also tried dynamic sql query like </p>
  
  <pre><code>Declare @subquery nvarchar(max)
  
  set @subquery=';With CTE2 as ( Select * from #Temp) select * from CTE2'
  
  INSERT INTO #Temp1 From (EXEC sp_executesql @subquery)
  </code></pre>
  
  <p>This also gives error...</p>
  
  <p><strong>More Things to know</strong>:</p>
  
  <p>i)I don't know about what are the columns will sub query returns</p>
  
  <p>ii)And I don't have any control in sub query . like what is syntax of subquery and how it looks like? </p>
  
  <p>so from these things,  even I can't use dynamic sql (<code>EXEC sp_executesql</code>).because I don't know what will happen if <code>@subquery</code> itself contains dynamic sql.</p>
  
  <p>Please help anyone... </p>