I have a table with a large number of columns. Among the columns are four columns that hold the expiry dates for different types of insurance. I need to write a query that counts the number of records, where the date difference on any of the four columns, between the date now and the expiry date is within the next 30 days. The data will eventually be used in a dashboard to flag the number of insurance policies expiring in the next 30 days, so the results will need to be grouped by company.
The following select statement will return all records where the expiry date is within the 30 days, but I am unable to turn this statement into a SELECT COUNT query without getting an error "You tried to execute a query that does not include the specified expression Expr2 as part of an aggregate function". Can anyone tell me what is wrong, and perhaps show me how to get this working.
SELECT (PI_EXPIRY_DATE) AS Expr1, (WC_expiry_date) AS Expr2, (EL_expiry_date) AS Expr3, (CAR_expiry_date) AS Expr4
FROM Company
WHERE (((Company.PI_EXPIRY_DATE)<Now()+30)) OR (((Company.WC_expiry_date)<Now()+30)) OR (((Company.EL_expiry_date)<Now()+30)) OR (((Company.CAR_expiry_date)<Now()+30));
I am a relative newbie at SQL, so would appreciate it if you assume no prior knowledge.
Thanks
The following select statement will return all records where the expiry date is within the 30 days, but I am unable to turn this statement into a SELECT COUNT query without getting an error "You tried to execute a query that does not include the specified expression Expr2 as part of an aggregate function". Can anyone tell me what is wrong, and perhaps show me how to get this working.
SELECT (PI_EXPIRY_DATE) AS Expr1, (WC_expiry_date) AS Expr2, (EL_expiry_date) AS Expr3, (CAR_expiry_date) AS Expr4
FROM Company
WHERE (((Company.PI_EXPIRY_DATE)<Now()+30)) OR (((Company.WC_expiry_date)<Now()+30)) OR (((Company.EL_expiry_date)<Now()+30)) OR (((Company.CAR_expiry_date)<Now()+30));
I am a relative newbie at SQL, so would appreciate it if you assume no prior knowledge.
Thanks