Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Calculating Year

Status
Not open for further replies.

renee35

MIS
Jan 30, 2007
199
0
0
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
 
try
SELECT EndDate
FROM FiscalWeekMap
WHERE dateadd(yy,-1, @PeriodStartDate) between WeekStartDate and WeekEndDate

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top