We help IT Professionals succeed at work.

Join on Expression gives an error

Michael Paravicini
on
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
Comment
Watch Question

Software Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT
Commented:
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 "" &
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
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.

Author

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