SQLTeam.com | Weblogs | Forums

Epllation of code


#1

hi i was wondering if anyone could help me explain what the -1 does in this code
WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To])-1,''19000701'')
AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To])-1,''19000930'')
THEN Net_Distributions_Paid_Amount

	 ELSE
		0.00
	 END 

and how would it affect date_to dates when one is 20151231 and the other is 20150630.

when i take the 1 away it works for 20151231 but not20150630.


#2

It seems your code is fixed at third quarter the year before date_to

With the "-1" the date range is third quarter the year before
Without the "-1" its the third quarter same year

So if date_to is:
20150630 as_of_date must be in range of 20140701 - 20140930
20151231 as_of_date must be in range of 20140701 - 20140930

If you remove the "-1":
20150630 as_of_date must be in range of 20150701 - 20150930
20151231 as_of_date must be in range of 20150701 - 20150930