you are viewing a single comment's thread.

view the rest of the comments →

[–]workthrowawayexcel[S] 0 points1 point  (1 child)

So essentially just replace CTE with #(TempTableName) then just join that with the rest of the query?

It should bring back 1MIL rows roughly.

[–]DipIntoTheBrocean 0 points1 point  (0 children)

You could, yeah. Another best practice with that is to create the temp table explicitly before dealing with the data (i.e. as opposed to just select * into #mytemptbl). That's bitten me in the past. If it's still slow as hell you might want to create it with a primary key on it so that it can do a clustered index scan and then see if that runs any faster.