Log in

View Full Version : Compare integer value of a text/string in OUTER JOIN ON clause (SQL in vba)



lillyanna
01-16-2013, 10:55 AM
I would like to execute the SQL statement below in vba code written for MS Access, and I want the integer values of the ID fields to be compared in the JOIN ON criteria. However, I get an error when using CInt(). I've also tried Val(), CAST(), and Convert().
Set RecordSet = "SELECT A.id, B.id FROM A LEFT OUTER JOIN B ON CInt(A.id)=CInt(B.id)"

the entire id contains only numbers. For example A.id=0123, and B.id=00123 . I want to compare the value integer of the two so that A.id=B.id is true.

Thanks!
Lillyanna

Doug Robbins
03-10-2013, 01:55 AM
Use Format(A.id, 0)=Format(B.id, 0)