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;
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.
Wait, there may be a missing left paren. Add a second one after the first one
- Clayton_cramerJan 26, 2021Copper Contributor
George_Hepworth I added that parenthesis and now I get "Your query does not include the specified expression 'lif([cause_ID]15 Or [cause_ID=16,count(year),0)' as part of an aggregate function.
SELECT year, Iif(([cause_ID] = 15 or [cause_ID]=16), count(year), 0) AS incidents
FROM Table2
GROUP BY year;
I would upload the database, but it is huge: every mass murder in American history from 1657 to 1914 (so far). year is a number, cause_ID is a number.
- George_HepworthJan 26, 2021Silver Contributor
Reread what you entered, please. What you posted here is now missing a closing square bracket. It's also missing an equal sign. Trouble-shooting often requires taking a closer, second look at things.
- Clayton_cramerJan 26, 2021Copper Contributor
I put everything in a format to simplify matching parens and brackets
SELECT year, iif (
(
(
[cause_ID] = 15
)
or
(
[cause_ID]=16
)
)
,
count(year), 0) -- matches opening ( of iif
AS incidentsFROM Table2
GROUP BY year;
All parens and brackets match. "Your query does not include the specified expression... as part of an aggregate function." I put the [cause_ID] clauses in their own parens to make sure iif was treating that as a single boolean operation. Even removing those parens, I get the same error message.