简体   繁体   中英

“Data type mismatch in criteria expression” when doing SQL subquery in Access 2010

Here is my simplified code (little more than some basic elements to cause the SQL not to execute):

select *
from (
    select replace(mytxtfield, "llama", "") as badones 
    from XYZ
)
where badones is not null;

The outer query runs fine when the WHERE cause is:

 badones like "ZZZ-[0-9][0-9][0-9]"

but it breaks when the WHERE cause includes more than one LIKE (of any digit matching pattern) such as:

badones like "ZZZ-[0-9][0-9]" OR 
badones like "ZZZ-[0-9][0-9][0-9]"

More info:

  • mytxtfield is of type Text
  • It doesn't matter if there is a WHERE cause in the inner query to check eliminate null / empty strings.
  • 64-bit office

Since your sub-query returns the alias "badnews", you must use it in place of "badones" in your outer query. The following produces no errors:

SELECT *
FROM (select replace(mytxtfield, "llama", "") as badnews 
    from XYZ
)  
WHERE (((badnews) Like "ZZZ-[0-9][0-9]" Or (badnews) Like "ZZZ-[0-9][0-9][0-9]"));

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