February 19, 2010 at 1:01 am
My requirement is,
I am passing some month names to query like as follows
January 2009,March 2009
Among the two months above the latest month is March 2009 , but i need to get all the months names from January 2009 to March 2009 and pass the same to another SP.
the issue is how to get the month names starting from january to the March?
Thanks in advance,
Venu Gopal.K
Software Engineer
INDIA
February 19, 2010 at 2:55 am
declare @monthname varchar(50)
set @monthname = 'January 2009,May 2009'
set @monthname = SUBSTRING(@monthname,PATINDEX('%,%', @monthname)+1,LEN(@monthname))
--for select last month May 2009
declare @concat nvarchar(1000)
select @concat=coalesce(@concat,'')+datename(m ,DATEADD(mm, N-1, '01/01/1900'))
+ ' '+cast(year(@monthname)as varchar)+','
FROM DBO.Tally /*Ref Jeff article for this numbers table*/
WHERE N <= month(@monthname)
SET @concat = SUBSTRING(@concat,1,LEN(@concat)-1)
select @concat
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply