jreed121
jreed121

Reputation: 2097

How to select every year from a particular year to the current year as different rows?

Say my start year is 2000 and I would like to have a one column select return every year from 2000 to the current year, example:

2000
2001
...
2012
2013

This is to populate a parameter in Reporting Services.

Upvotes: 0

Views: 60

Answers (1)

Taryn
Taryn

Reputation: 247880

The easiest thing for you to do would be to create a numbers table that you would use for these types of queries.

You could also use a recursive Common Table Expression to generate the list of years:

;with cte (yr) as
(
  select 2000
  union all
  select yr + 1
  from cte
  where yr+1 <=2013
)
select yr
from cte;

See SQL Fiddle with Demo

Upvotes: 2

Related Questions