Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 get the month names between two dates

Author  Topic 

headbuzz
Starting Member

11 Posts

Posted - 2010-06-03 : 12:21:52
I have two dates: subscriptionstartdate and subscriptionenddate. My goal is to display all the month names between and including these two dates. Suppose the dates are 1/2/2009 and 3/6/2009, I need to get the output as february, march,april,may,june. I used the following but it only returns as a broken response (multiple outputs, which I cannot use to bind any element in the front end).

declare @t as int
declare @i as int
declare @k as int
set @k=0
set @i=(select month(SubscriptionStartDate) from Subscriber where SubscriberID=10000002)
set @t=(select month(SubscriptionEndDate) from Subscriber where SubscriberID=10000002)
while @i<@t
begin
select datename(month,dateadd(month, month(SubscriptionStartDate) - 1+@k, 0)) as MonthName from Subscriber where SubscriberID=10000002
-
set @i=@i+1
set @k=@k+1
end

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-06-03 : 12:31:13
I just answered this where you originally posted it..hope it's what you're looking for!

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -