I am trying to use the \"WITH\" statement in SQL Server 2005. It seems to work fine if I do something like:
WITH MyBigProducts AS (SELECT * FROM Products WHE
CTE have statement local scope and visibility. If you want greater scope and visibility for a table expression, you would need to make the CTE into a View or table-valued function.
Alternatively, you can materialize the expressions results into a table variable, which is local to the current batch or a temporary table whose lifetime is also local to the current batch, but whose visibility extends to the whole session.