>>It doesn't have to be a temp table, it can be a CTE, e.g.
>>
>>;with cte as (select Numero from .. where ..)
>>
>>select ... JOIN cte ...
>>
>>
>>
>>You may want to try that approach as well. I'll check the execution plan screen later, currently trying to figure out weird VFP problem with debugging code.
>
>I was thinking the same thing, either a cte or a sub-query (select from.. where numero in (select numero...from .... join...)), i do not see the need of a temp table (although internally SQL is just doing that, right?)
I don't think internally SQL Server will create a temp table in case of cte. I think in this case it will be in memory. But it's a complex problem and I may need to re-read a few articles on this topic to be absolutely sure.
If it's not broken, fix it until it is.
My Blog