renee35
MIS
- Jan 30, 2007
- 199
I need any help that I can get. What I am trying to do is pull data based on the parameter @qtr. I need to figure out how to set the date range so SQL will know what Q1, Q2, etc. should include. Below is what I currently have:
DECLARE @StartDate datetime
DECLARE @EndDate datetime
DECLARE @YearStartDate datetime
DECLARE @RunDate datetime
DECLARE @Official int
DECLARE @Qtr int
DECLARE @Userdate int
DECLARE @Year varchar (4)
-- determine dates for @qtr parameter
select
@userdate = case
when @qtr = 1 then '1/1'
when @qtr = 2 then '4/1'
when @qtr = 3 then '7/1'
when @qtr = 4 then '10/1'
when @qtr = 5 then '1/1' + @year-- should include entire year?
end
SET @Rundate = getdate()
SET @StartDate = cast(cast(month((@qtr*3)-2) as varchar(1)) + '/1/' + cast(@year as varchar(4)) as datetime)
SET @EndDate = cast(cast(month(@qtr*3) as varchar(1)) + '/1/' + cast(@year as varchar(4)) as datetime)
SET @YearStartDate = dateadd (yy, datediff(yy,0,@Qtr),0) --'1/1/2008'
SET @Qtr = 3
SET @Year = 2008
I am not returning any data? I know something is not right with the way the @qtr is set up because without it I get results back!
Thanks a bunch!!!!
Thanks a bunch!!
-T
DECLARE @StartDate datetime
DECLARE @EndDate datetime
DECLARE @YearStartDate datetime
DECLARE @RunDate datetime
DECLARE @Official int
DECLARE @Qtr int
DECLARE @Userdate int
DECLARE @Year varchar (4)
-- determine dates for @qtr parameter
select
@userdate = case
when @qtr = 1 then '1/1'
when @qtr = 2 then '4/1'
when @qtr = 3 then '7/1'
when @qtr = 4 then '10/1'
when @qtr = 5 then '1/1' + @year-- should include entire year?
end
SET @Rundate = getdate()
SET @StartDate = cast(cast(month((@qtr*3)-2) as varchar(1)) + '/1/' + cast(@year as varchar(4)) as datetime)
SET @EndDate = cast(cast(month(@qtr*3) as varchar(1)) + '/1/' + cast(@year as varchar(4)) as datetime)
SET @YearStartDate = dateadd (yy, datediff(yy,0,@Qtr),0) --'1/1/2008'
SET @Qtr = 3
SET @Year = 2008
I am not returning any data? I know something is not right with the way the @qtr is set up because without it I get results back!
Thanks a bunch!!!!
Thanks a bunch!!
-T