All of my data have a "Number of Positions" filled in on the table, but when I run this query only the items that have Elected=y and Inc=I show a Count of Number of Positions. Can I get a Count to equal 0 if it doesn't meet the criteria? Even with this IIf statement (in red), there are no null values showing in my query results.
SQL reads:
SELECT TblTrustees.[Authority Code], TblTrustees.[Authority Name], Count(TblTrusteesPerAuthority.[Number of Positions]) AS [CountOfNumber of Positions], TblTrustees.[Incumbent (I) New (N) Vacant (V)], TblTrustees.Elected, IIf([CountofNumber of Positions] Is Null,0,[CountofNumber of Positions]) AS ElecInc
FROM TblTrustees INNER JOIN TblTrusteesPerAuthority ON TblTrustees.[Authority Code] = TblTrusteesPerAuthority.[Authority Code]
GROUP BY TblTrustees.[Authority Code], TblTrustees.[Authority Name], TblTrustees.[Incumbent (I) New (N) Vacant (V)], TblTrustees.Elected
HAVING (((TblTrustees.[Incumbent (I) New (N) Vacant (V)])="i") AND ((TblTrustees.Elected)="y"));
SQL reads:
SELECT TblTrustees.[Authority Code], TblTrustees.[Authority Name], Count(TblTrusteesPerAuthority.[Number of Positions]) AS [CountOfNumber of Positions], TblTrustees.[Incumbent (I) New (N) Vacant (V)], TblTrustees.Elected, IIf([CountofNumber of Positions] Is Null,0,[CountofNumber of Positions]) AS ElecInc
FROM TblTrustees INNER JOIN TblTrusteesPerAuthority ON TblTrustees.[Authority Code] = TblTrusteesPerAuthority.[Authority Code]
GROUP BY TblTrustees.[Authority Code], TblTrustees.[Authority Name], TblTrustees.[Incumbent (I) New (N) Vacant (V)], TblTrustees.Elected
HAVING (((TblTrustees.[Incumbent (I) New (N) Vacant (V)])="i") AND ((TblTrustees.Elected)="y"));
Last edited: