There are two solutions for this.
- Modify your current where statement and add a condition to check for this case.
- Use
DATEADD
function. Present in comments and other answer(s).
Modifying your where to add Condition
Note: Minor error may exists since I need to check if January has month value of zero or 1.
Example:
WHERE
(
'@Request.parmMonth~'-2 < 1 AND
YEAR(Main.ActivityDate) = '@Request.parmYear~'-1 AND
Month(Main.ActivityDate) Between
(12+'@Request.parmMonth~'-2) AND 12
)
OR
(
YEAR(Main.ActivityDate) = '@Request.parmYear~'
AND (Month(Main.ActivityDate) Between
('@Request.parmMonth~'-2) and '@Request.parmMonth~'
)