• hi, hi don't see the advantage of CTE to temp Tables like in the example below. Is there any advantage?

    WITH

    CountEmployees(dept_id, n) AS

    ( SELECT dept_id, count(*) AS n

    FROM employee GROUP BY dept_id ),

    DeptPayroll( dept_id, amt ) AS

    ( SELECT dept_id, sum(salary) AS amt

    FROM employee GROUP BY dept_id )

    select v.* into #CountEmployees from

    (SELECT dept_id, count(*) AS n

    FROM employee GROUP BY dept_id)v

    select v.* into #DeptPayroll from

    (SELECT dept_id, sum(salary) AS amt

    FROM employee GROUP BY dept_id)v