From: Plamen Ratchev on
simon wrote:

> As I know if you use CTE, SQL in behind also create some type of temp
> table or variable, doesn't it? So it shouldn't be so different.
>

This is incorrect. While some results may be materialized during processing in tempdb, CTEs are not materialized behind
the scenes to temp table/variable. Currently the best approach is to store the result set to temporary table and reuse.

--
Plamen Ratchev
http://www.SQLStudio.com
From: simon on
On 18 feb., 16:05, Plamen Ratchev <Pla...(a)SQLStudio.com> wrote:
> simon wrote:
> > As I know if you use CTE, SQL in behind also create some type of temp
> > table or variable, doesn't it? So it shouldn't be so different.
>
> This is incorrect. While some results may be materialized during processing in tempdb, CTEs are not materialized behind
> the scenes to temp table/variable. Currently the best approach is to store the result set to temporary table and reuse.
>
> --
> Plamen Ratchevhttp://www.SQLStudio.com

Thank you for your answer. I use CTE where I can, but in this case I'm
stucked with temp table.

Regards,
Simon