SELECT ContestID, count(*) AS MissingHoles FROM (SELECT DISTINCT ContestId, Hole FROM tblContestDetails WHERE CourseId=[CourseId] and Score is null) AS qry GROUP BY ContestID;
You can close, save, and execute this query just fine. However, when you go back in to edit the query, it now looks like this:
SELECT ContestID, count(*) AS MissingHoles FROM [SELECT DISTINCT ContestId, Hole FROM tblContestDetails WHERE CourseId=[CourseId] and Score is null]. AS qry GROUP BY ContestID;
Note that the subquery is now enclosed in square brackets instead of parenthesis. The only problem is that if you make a change to this new query (e.g. add a space somewhere) and try to save it, you will be presented with an error:
"Invalid bracketing of name 'SELECT DISTINCT ContestId, Hole FROM tblContestDetails WHERE CourseId=[CourseId'."
The solution is to put the parenthesis back around the subquery every time you want to save. :-(
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.