Within SQL Server is it at all possible to wrap a string of CTE's into just one temporary table in SQL?
Not all of the CTE's have equal amount of columns in nor are they the same data type so a UNION ALL is not possible, I thought the below may work however clearly I'm getting syntax errors:
SELECT * INTO #TEMP FROM (
;with firstCTE AS (
SELECT ColA
,ColB
,Colc
FROM tbl1
)
,secondCTE AS (
SELECT ColD
,ColE
FROM tbl2
)
,thirdCTE AS (
SELECT ColF
FROM tbl3
)
)
-- Selecting all of the data from the CTE's above
SELECT * FROM #TEMP
It depends on what you want to achieve:
Keep in mind that a LEFT JOIN might not be what you need. Change to the proper JOIN condition that would work for you