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.

more ▼

asked Mar 20, 2013 at 02:43 PM in Default

avatar image

338 20 22 27

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 20, 2013 at 02:47 PM

avatar image

40.9k 39 95 168

Thanks Tim that was simple, I way over did that with the while counter.

Mar 20, 2013 at 03:19 PM tombiernacki
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Mar 20, 2013 at 02:43 PM

Seen: 1209 times

Last Updated: Mar 20, 2013 at 03:19 PM

Copyright 2018 Redgate Software. Privacy Policy