Maliks, I suppose, some were confused with your SQL. It was not immediately apparent that you use a recursive CTE to generate years in a range. There are lots of awesome ways to generate a sequence of integers (or numbers, in general) that can be combined with a CTE to emulate variables in a view. If numbers are generated way too often, consider building a separate (and indexed) table for them.
Here is what I think you were looking for. I omit the CTEs, rank
and grouping you have not defined in your question. You can modify it as you wish:
WITH params AS (SELECT BegYr = 2005, EndYr=2014),
nums AS (SELECT DISTINCT n = number FROM master..spt_values WHERE number>=0)
SELECT Yr=BegYr + n FROM nums, params
WHERE n <= EndYr - BegYr
More generally, here is a sample view query that uses CTE to nicely emulate internal variable construction. You can test-run it in your version of SQL Server.
CREATE VIEW vwImportant_Users AS
WITH params AS (
SELECT
varType='%Admin%',
varMinStatus=1)
SELECT status, name
FROM sys.sysusers, params
WHERE status > varMinStatus OR name LIKE varType
SELECT * FROM vwImportant_Users
yielding output:
status name
12 dbo
0 db_accessadmin
0 db_securityadmin
0 db_ddladmin
also via JOIN
WITH params AS ( SELECT varType='%Admin%', varMinStatus=1)
SELECT status, name
FROM sys.sysusers INNER JOIN params ON 1=1
WHERE status > varMinStatus OR name LIKE varType
also via CROSS APPLY
WITH params AS ( SELECT varType='%Admin%', varMinStatus=1)
SELECT status, name
FROM sys.sysusers CROSS APPLY params
WHERE status > varMinStatus OR name LIKE varType