简体   繁体   中英

SQL Data type mismatch in criteria expression MS Access

I have a problem.

When I try to run this query:

SELECT Artiesten.ID AS txtArtiestId, 
NULL AS txtAlbumId, 
NULL AS txtNummerId, 
Artiestnaam AS Artiesten, 
NULL AS Albums, 
NULL As Nummers 
FROM Artiesten 
WHERE Artiesten.Artiestnaam LIKE '*On*' 

UNION ALL

SELECT 
Artiesten.ID AS txtArtiestId, 
Albums.ID AS txtAlbumId, 
NULL AS txtNummerId, 
Artiesten.Artiestnaam AS 
Artiesten, Naam AS Albums, 
NULL As Nummers 
FROM Albums 
INNER JOIN Artiesten ON Albums.ArtiestId = Artiesten.ID 
WHERE  albums.naam LIKE '*On*'

UNION ALL

SELECT 
Artiesten.ID AS txtArtiestId, 
Albums.ID AS txtAlbumId, 
Nummers.ID AS txtNummerId, 
Artiesten.Artiestnaam AS Artiesten, 
Albums.Naam AS Albums, 
Nummers.Naam AS Nummers 
FROM  (Nummers INNER JOIN Albums ON Nummers.AlbumId = Albums.ID)
INNER JOIN Artiesten ON Albums.ArtiestId = Artiesten.ID
WHERE  Nummers.Naam LIKE '*On*'

It says:

"Data type mismatch in criteria expression"

Now I already know that it has to do something with the first and the last query. Those 2 together are causing the error.

What am I doing wrong?

You might be able to fix this by providing NULL with the appropriate type in the first query:

SELECT Artiesten.ID AS txtArtiestId, 
       int(NULL) AS txtAlbumId, 
       int(NULL) AS txtNummerId, 
       Artiestnaam AS Artiesten, 
       str(NULL) AS Albums, 
       str(NULL) As Nummers 
FROM Artiesten 
WHERE Artiesten.Artiestnaam LIKE '*On*'

Actually, I'm not sure what the right types are. I'm just guessing.

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