Skip to content Skip to sidebar Skip to footer

CTE In From Clause Of SQL Query

I need to use CTE query inside from clause of SQL Query See this example: Drop Table #Temp Drop Table #Temp2 Create Table #Temp(name1 text, name2 text) Insert INTO #Temp Values ('

Solution 1:

Check with below syntax, its worked for me and i hope you are looking for same:

With CTE as ( Select * from #Temp) 
select * into #Temp2 from CTE

Solution 2:

use below query



  Create Table #Temp(name1 text, name2 text)

    Insert INTO #Temp Values ('test','test')
    Insert INTO #Temp Values ('test','test')
    GO

    With CTE as ( Select * from #Temp) 
    select * into #Temp2 from CTE

    select * from #Temp2
    GO
    Drop Table #Temp
    Drop Table #Temp2

Post a Comment for "CTE In From Clause Of SQL Query"