I have a table with a date for an event, and for esoteric reasons I want to flag if the event happened in the first quarter of the year. Should be simple, right?
(Background, the esoteric reason is that I need to treat the first quarter of the year as part of the previous year. Sort of like an odd fiscal year.)
Pulling the month out of the date is easy. Example query:
SELECT “StartDate” AS “ADate”, MONTH( “StartDate”) AS “Result” FROM “TabBills”
And I can do arithmetic calculations on the month:
SELECT “StartDate” AS “ADate”, MONTH( “StartDate” ) + 1 AS “Result” FROM “TabBills”
(Not that that’s useful, but it shows at least some calculation is allowed.)
But any logic-based operation fails. For example:
SELECT “StartDate” AS “ADate”, (MONTH( “StartDate” ) < 4) AS “Result” FROM “TabBills”
(With or without the parens) I’d expect to get a TRUE for the first quarter and FALSE after. Instead I just get Syntax error in SQL statement.
I also tried
SELECT “StartDate” AS “ADate”, MONTH( “StartDate” ) IN (1, 2, 3) AS “Result” FROM “TabBills”
No joy there, either. I’m obviously missing something fundamental. Any suggestions for how to do this?
I’d hate to have to join to a table that has 12 rows:
1 TRUE
2 TRUE
3 TRUE
4 FALSE
…