Forum Discussion
Inserting empty rows
- Feb 04, 2021
Clayton_cramer If you don't like IIF, then use IN:
SELECT year, Abs(Sum([cause_ID] In (15, 16))) AS incidents FROM Table2 GROUP BY year;
If you want to see all years regardless of whether there are any matching cause_IDs for those years, then you can't use the WHERE clause to exclude them.
Instead, you need to use a conditional for the Count(year) to return the actual Count where there are matching cause_IDs or 0 where there are none.
SELECT year, Iif([cause_ID] = 15 or [cause_ID]=16), count(year), 0) AS incidents
FROM Table2
GROUP BY year;
- Clayton_cramerJan 26, 2021Copper Contributor
wrong number of arguments used in query function lif([cause_ID) = 15 or [cause_ID]=16'.
- Clayton_cramerJan 26, 2021Copper Contributor
Clayton_cramerlif looks like a typo for if, but "undefined function 'if' in expression."
- George_HepworthJan 26, 2021Silver Contributor
Iif() is the immediate If function; that's how it is spelled.
There must be a different syntax error in my suggested approach. It's aircode since I don't have visibility to your actual table(s). See if you can suss it out, but post back if not.