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
I believe that Common Table Expressions are only valid for immediate use which is why you are getting an error for the "SELECT Count(*) FROM MyBigProducts". In order to reuse a CTE you should use a temporary table instead
DECALRE @BigProducts TABLE (...[declaration omitted]...)
INSERT INTO @BigProducts
SELECT *
FROM Products
WHERE Size='Big'
SELECT Name FROM @BigProducts
SELECT Count(*) FROM @BigProducts
Please correct me if I am wrong.