renee35
MIS
- Jan 30, 2007
- 199
I have a query that I have created with a parameter of @Qtr and based on this there is a @start and @end date, see below:
SET @Qtr = 3
SET @Year = 2008
-- determine dates for @qtr parameter
select @StartDate = case
when @qtr = 1 then '1/1/' + Convert(VarChar(4), @Year)
when @qtr = 2 then '4/1/' + Convert(VarChar(4), @Year)
when @qtr = 3 then '7/1/' + Convert(VarChar(4), @Year)
when @qtr = 4 then '10/1/' + Convert(VarChar(4), @Year)
when @qtr = 5 then '1/1/' + Convert(VarChar(4), @year)-- should include entire year?
-- Should not happen
end,
@EndDate = Case
when @qtr = 1 then Convert(DateTime, '4/1/' + Convert(VarChar(4), @Year)) - 1
when @qtr = 2 then Convert(DateTime, '7/1/' + Convert(VarChar(4), @Year)) - 1
when @qtr = 3 then Convert(DateTime, '10/1/' + Convert(VarChar(4), @Year))- 1
when @qtr = 4 then Convert(DateTime, '1/1/' + Convert(VarChar(4), @Year + 1)) - 1
when @qtr = 5 then Convert(DateTime, '1/1/' + Convert(VarChar(4), @year + 1)) - 1 -- should include entire year?
end
Now what I am trying to do is when I select @qtr = 3, how can I indicate in my code:
where a.date is between "previous qtr @end" and a.closedate?
My issue is how to I go about getting the "previous qtr @end" date? In this case it would be @qtr2 end date.
Thanks a bunch?
Thanks a bunch!!
-T
SET @Qtr = 3
SET @Year = 2008
-- determine dates for @qtr parameter
select @StartDate = case
when @qtr = 1 then '1/1/' + Convert(VarChar(4), @Year)
when @qtr = 2 then '4/1/' + Convert(VarChar(4), @Year)
when @qtr = 3 then '7/1/' + Convert(VarChar(4), @Year)
when @qtr = 4 then '10/1/' + Convert(VarChar(4), @Year)
when @qtr = 5 then '1/1/' + Convert(VarChar(4), @year)-- should include entire year?
-- Should not happen
end,
@EndDate = Case
when @qtr = 1 then Convert(DateTime, '4/1/' + Convert(VarChar(4), @Year)) - 1
when @qtr = 2 then Convert(DateTime, '7/1/' + Convert(VarChar(4), @Year)) - 1
when @qtr = 3 then Convert(DateTime, '10/1/' + Convert(VarChar(4), @Year))- 1
when @qtr = 4 then Convert(DateTime, '1/1/' + Convert(VarChar(4), @Year + 1)) - 1
when @qtr = 5 then Convert(DateTime, '1/1/' + Convert(VarChar(4), @year + 1)) - 1 -- should include entire year?
end
Now what I am trying to do is when I select @qtr = 3, how can I indicate in my code:
where a.date is between "previous qtr @end" and a.closedate?
My issue is how to I go about getting the "previous qtr @end" date? In this case it would be @qtr2 end date.
Thanks a bunch?
Thanks a bunch!!
-T