Simple question, are the results of a CTE stored in the same place as a temp table (tempdb)?
As with a View or any query, for that matter, they might not be stored at all. Proof of that is if you call the CTE twice as a self join. If you look at the execution plan, you'll see that the CTE actually had to run twice. Any interim storage required by a query, for a working table to support a hash join for example, will make use of TempDB.
That being said, TempDB is NOT disk only. If the optimizer can and does allocate memory for the task, the TempDB part of it will be done in memory. Similarly (and just to be sure), Table Variables are NOT memory only. They will spill to disk if they get too big.
is pronounced ree-bar and is a Modenism for R
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Helpful Links:
How to post code problemsHow to post performance problemsForum FAQs