SQL 2005 has a new feature called Common Table Expression (CTE). You don’t need to use table variable any more. It is more powerful. You can use it for recursive query, aggregation query etc. Ex.
_WITH tmpa (col1, col2, col3)
AS
(
SELECT col1, col2, col3 FROM a WHERE a.flag = 1
)
_SELECT * FROM tmp_a
WHERE tmpa.col1 like ‘aa%’