So, i have a query and have several strings of CTEs as part of my query and at some point things slow down, a great deal. One of my last CTES we’ll call bigtable and following are minitable1, minitable2…which are all subsets of bigtable where criteria1 and criteria2 are met.
If i do a select * from bigtable, the query runs in a reasonable amount of time.
If i do a select * from any of my minitables, the query takes an irrationally long amount of time.
To get around this, a coworker suggested i make a temp table of bigtable, which sounds good, but bigtable is the result of several CTEs.
Can making a temptable be as simple as
create table #importanttemptable as
select * from
(
with cte1 as (…)
, cte2 as (…)
…
, bigtable as (…)
select * from bigtable
)
?
What’s the easiest way to make a temp table out of a CTE, several CTEs in the making?
Till all are one, Epistemus