I am having following scenario
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
)
I know we can't use CTE as subquery .. but for hard time I don't know exact syntax of subquery since it is being provided by other system.
just image this
Insert Into #Temp1 Select * From
(
"Query Provided by Other System"
)
So I don't have any control on subquery ("Query Provided by Other System").. And I have also tried dynamic sql query like
Declare @subquery nvarchar(max)
set @subquery=';With CTE2 as ( Select * from #Temp) select * from CTE2'
INSERT INTO #Temp1 From (EXEC sp_executesql @subquery)
This also gives error...
More Things to know:
i)I don't know about what are the columns will sub query returns
ii)And I don't have any control in sub query . like what is syntax of subquery and how it looks like?
so from these things, even I can't use dynamic sql (EXEC sp_executesql).because I don't know what will happen if @subquery itself contains dynamic sql.
Please help anyone...
WITHwith;. The;is there to define the end of a statement. The usual (bad) habit to prefixwithwith;is only there to ensure the previous statement was terminated properly.