This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output to find the list of Years between Start Year and End Year.
Input data:
1 2 |
Start Year = 2008 End Year = 2017 |
Expected Output:
1 2 3 4 5 6 7 8 9 10 11 12 |
Years ----------- 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 |
Solution:
1 2 3 4 5 6 7 8 9 10 11 |
DECLARE @StartYear AS INT = 2008 DECLARE @EndYear AS INT = 2017 SELECT DISTINCT Numbers as Years FROM ( SELECT DISTINCT @StartYear + number as Numbers FROM Master..Spt_Values WHERE number >= 0 and number <= (@EndYear - @StartYear) )t ORDER BY Numbers |
Please try the different solution for this puzzle and share it via comment...