See DATEADD()
select convert(datetime,'6/1/2010')
select DATEADD(day,-1,DATEADD(month,1,convert(datetime,'6/1/2010'))) --6/30/2010
select DATEADD(month,1,convert(datetime,'6/1/2010')) --7/1/2010
You would likely run this in a stored procedure which would generate a temp table, or quick and really dirty just one big query...
I hesitate to just do the whole thing for you, but what the hay...
create procedure getFiscalYear
@startDate nvarchar(10)
as begin
declare @myDate datetime
set @myDate = convert(datetime,@startDate)
select 1 as Period, @myDate as startDate, DATEADD(day,-1,DATEADD(month,1,@myDate)) as endDate
union
select 2 as Period, DATEADD(month,1,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,2,@myDate)) as endDate
union
select 3 as Period, DATEADD(month,2,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,3,@myDate)) as endDate
union
select 4 as Period, DATEADD(month,3,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,4,@myDate)) as endDate
union
select 5 as Period, DATEADD(month,4,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,5,@myDate)) as endDate
union
select 6 as Period, DATEADD(month,5,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,6,@myDate)) as endDate
union
select 7 as Period, DATEADD(month,6,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,7,@myDate)) as endDate
union
select 8 as Period, DATEADD(month,7,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,8,@myDate)) as endDate
union
select 9 as Period, DATEADD(month,8,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,9,@myDate)) as endDate
union
select 10 as Period, DATEADD(month,9,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,10,@myDate)) as endDate
union
select 11 as Period, DATEADD(month,10,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,11,@myDate)) as endDate
union
select 12 as Period, DATEADD(month,11,@myDate) as startDate, DATEADD(day,-1,DATEADD(month,12,@myDate)) as endDate
end
that's the ugly way...