renee35
MIS
- Jan 30, 2007
- 199
I have the below code and it is not giving me the correct return value:
DECLARE @PeriodStartDate datetime
DECLARE @LastYTD datetime
DECLARE @EndDate datetime
SET @EndDate = '2009-2-15'
select @PeriodStartDate = StartDate from FiscalWeekMap where EndDate = @EndDate
SELECT @LastYTD = Max(EndDate) from FiscalWeekMap where WorkYear = Year(@PeriodStartDate)-1
PRINT @PeriodStartDate
PRINT @LastYTD
Returns:
Feb 9 2009 12:00AM
Jan 4 2009 12:00AM
I am trying to get Jan 4 2009 to be the Feb 9, but year 2008 based on this part of the code:
Year(@PeriodStartDate)-1
Please advise as to what I am doing wrong. Thanks!
Thanks a bunch!!
-T
DECLARE @PeriodStartDate datetime
DECLARE @LastYTD datetime
DECLARE @EndDate datetime
SET @EndDate = '2009-2-15'
select @PeriodStartDate = StartDate from FiscalWeekMap where EndDate = @EndDate
SELECT @LastYTD = Max(EndDate) from FiscalWeekMap where WorkYear = Year(@PeriodStartDate)-1
PRINT @PeriodStartDate
PRINT @LastYTD
Returns:
Feb 9 2009 12:00AM
Jan 4 2009 12:00AM
I am trying to get Jan 4 2009 to be the Feb 9, but year 2008 based on this part of the code:
Year(@PeriodStartDate)-1
Please advise as to what I am doing wrong. Thanks!
Thanks a bunch!!
-T