I am trying date control by month with this script
DECLARE @Date DATETIME = '2015-07-31';
DECLARE @MonthCount INT = 3;
DECLARE @controlDate DATETIME = '2015-04-28';
SELECT
MONTH(@controlDate),
MONTH(DATEADD(MONTH, -@MonthCount, @Date)),
IIF(MONTH(@controlDate) > MONTH(DATEADD(MONTH, -@MonthCount, @Date)),'OK','No') as isOK
But I am getting this syntax error:
Msg 102, Level 15, State 1, Line 8 Incorrect syntax near '>'
EDIT:
When I try if
it is working:
DECLARE @Date DATETIME = '2015-07-31';
DECLARE @MonthCount INT = 3;
DECLARE @controlDate DATETIME = '2015-04-28';
if(MONTH(@controlDate) > MONTH(DATEADD(MONTH, -@MonthCount, @Date)))
print 'OK'
else
print 'No'
What am I doing wrong or is this a bug?