Is there a way to place the following code into a SELECT routine in a stored procedure?:
--- Using a CTE (Common Table Expression) "t" to gather all the data from the
--- [a2hr].[dbo].[PyRlByPeriod] "PRBP" table
WITH t ([Year], Period, week, DIALER) AS
(SELECT PRBP.Year
, PRBP.Period
, PRBP.WEEK
, PRBP.DIALER
FROM [a2hr].[dbo].[PyRlByPeriod] PRBP)
SELECT t.Year
, t.Period
, t.WEEK
, t.DIALER
FROM t
GROUP BY Year, Period, Dialer
UNION
SELECT t.Year
, t.Period
, t.WEEK
, t.DIALER
FROM t
GROUP BY Year, Period, Dialer