We help IT Professionals succeed at work.

Join on Expression gives an error

Michael Paravicini
I have a table Pax (PaxId, PaxName) and a query qryPaxRooms (RoomPaxId, PaxName). RoomPaxId in the query is an expression with Nz(ResRooms.PaxId,ResPaxid) AS RoomPaxId. So if a reservation has no rooms yet assigned RoomPaxId will have the PaxId of the reservation otherwise the PaxId of the Room Owner (might be different). Now if I try to join table qryPaxRooms with a different table Invoices (InvID, InvDate, PaxId) on qryPaxRooms.RoomPaxId with Invoices.PaxId I get a type mismatch error. Is it not possible to do a join on expressions? Is there a different solution? Thank you so much for any help! Regards Michael
Watch Question

Software Tead Lead / Business Analyst / System Analyst / Data Engineer
I get a type mismatch error.

the most common reason is one of the field is a Text while another one comes with Int/numeric field.

Is it not possible to do a join on expressions

sure, perhaps try to convert the values to chars for comparison, like:

"" & Invoices.PaxId = "" & qryPaxRooms.RoomPaxId

Open in new window

noted that the additional "" &
Most Valuable Expert 2015
Distinguished Expert 2018

As your IDs probably are numeric, try to force a Long for the ID:

CLng(Nz(ResRooms.PaxId,ResPaxid)) AS RoomPaxId
Or you could attach a database with sample values.


Thank you to both of you for your help. Best regards Michael