Good afternoon,
I am trying to write a SQL statement that will evaluate column "DCN" and return only those records that say "5". Then, this statement (or possibly a second statement or embeded statement) will look at the "TFi_RM" column and perform an IIF. If the row is equal to 1, then return "MVP". If the row is equal to 0.9965, then return "All-Star". Otherwise, if neither criteria is met either return "No" or just don't select the column. I used the design builder for SQL with the expression builder and came up with the SQL statement below.
The purpose is to identify employees who received either no errors (MVP) or only had a single error (All-Star) during the week. It is a recognition program that we run internally.
When I run the statement, the error message says "You tried to execute a query that does not include the specified expression 'TFi_RM' as part of an aggregate function."
Code:
SELECT Weekly_Scores_RM.RMs_X, Weekly_Scores_RM.Week_x, Weekly_Scores_RM.DCN_x, Weekly_Scores_RM.TFi_RM
FROM Weekly_Scores_RM
GROUP BY Weekly_Scores_RM.RMs_X, Weekly_Scores_RM.Week_x, Weekly_Scores_RM.DCN_x
HAVING (((Weekly_Scores_RM.DCN_x)=5) AND ((Weekly_Scores_RM.TFi_RM)=IIf([TFi_RM]=1,"MVP","No"))) OR (((Weekly_Scores_RM.TFi_RM)=IIf([TFi_RM]=0.9965,"All-Star","No")));