question

tombiernacki avatar image
tombiernacki asked

get year dates stored procedure

Hi I have question about the best way to get multiple year dates based on the Year I select in my stored procedure. I declared a table variable and inserted years 2008 through 2014. So for example when I select year 2008 in my SP, I want to receive all the years 2008 through 2014. If I select year 2010 I will get 2010 through 2014 and if I select 2013, I will get 2013 through 2014 etc. Also What I have done is created a while counter but it does not work the way I want it because it does not start with the year I selected. Below Is what I have.... *set @year = 2010 set @year = @year while @year < 2014 begin SET @year = @year + 1 select @year as FISCAL_YEAR end* Any help or other ideas would be appreciated. Thanks in advance.
stored-proceduresdatewhile-loop
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Tim avatar image
Tim answered
If you are passing the year to the stored procedure and wish to return that year plus any years greater than that year simply have the where statement state >= @year.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tombiernacki avatar image tombiernacki commented ·
Thanks Tim that was simple, I way over did that with the while counter.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.