简体   繁体   中英

'data type mismatch in criteria expression' after Access query

I'm trying to count the total number of separate values in a query I've created in Access 2010 but I get an error message reading 'data type mismatch in criteria expression.' I can't see what that might be.

This is the query:

SELECT 
SUM(IIF(n.recall_method = "SMS",1 ,0)) AS SMS,
SUM(IIF(n.recall_method = "Letter",1 ,0)) AS Letter,
SUM(IIF(n.recall_method = "Practice invite",1 ,0)) AS [Practice Invite],
SUM(IIF(n.recall_method = "Advised to self-book",1 ,0)) AS [Advised to self-book],
SUM(IIF(n.recall_method is null,1 ,0)) AS [No Recall Method]

FROM  no_vaccine_or_care_home_vw AS n;

n.recall_method is ultimately pulling from a text field in a table but via a separate query, which itself relies on another query. In case the problem is arising here, here's the SQL for these:

no_vaccine_or_care_home_vw:

SELECT a.nhs_number, r.recall_method
FROM (all_patients_care_home_or_vacc_status_vw AS a 
LEFT JOIN patient_tbl AS p ON a.nhs_number=p.nhs_number) 
LEFT JOIN patient_recall_tbl AS r ON a.nhs_number=r.nhs_number
WHERE a.care_home is null 
AND a.vaccinated is null
AND age(p.date_of_birth)>17;

(age is a function calculating age from date of birth)

all_patients_care_home_or_vacc_status_vw:

SELECT n.nhs_number, 
 c.nhs_number AS care_home, 
 v.nhs_number AS vaccinated
FROM (nhs_no_tbl AS n 
LEFT JOIN patient_care_home_tbl AS c ON n.nhs_number = c.nhs_number) 
LEFT JOIN patient_vaccinated_tbl AS v ON n.nhs_number = v.nhs_number;

(Any object ending in _tbl is a table, unsurprisingly.)

Thanks for any help.

It will fail if you pass Null to the function, so prevent that, for example like this:

AND age(Nz(p.date_of_birth, Date()))>17;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM