Last post Oct 10, 2012 04:12 PM by Metaferia
Oct 09, 2012 12:22 PM|Metaferia|LINK
Here is the code i currently use, it worked fine till this month. The code is supposed to return result of
But I now relized it's not showing January 2013 data, I guess i need to add some kind of year checker so if current year + 3 is more than 12 then use current year + 1. But i'm not sure how i can inlucde that condition in SQL.
SELECT * FROM [xxxx] where sent like '%U%' and Month(dateofservice) = (Month(GetDate())+3)AND Year(dateofservice) = Year(GetDate()) ORDER BY [dateofservice] DESC
Any tip will be appriciated
Oct 09, 2012 12:46 PM|Dan Bracuk|LINK
I suggest creating variables that represent the 1st day of 3 months into the future and the first day 4 months in the future. Then your sql would be
and DateOfService >= @var1
and DateOfService < @var2
This approach will probably run faster too, especially if DateOfService is indexed.
Oct 10, 2012 04:12 PM|Metaferia|LINK
Thanks, i solved my problem by using variables.