Web Development
3 replies
by steved
Unlike SQL Server, Access won't automatically convert data types when you write a join on a string field with a numeric field. It also doesn't seem to allow the VBA function CStr in Access SQL, but it does allow user-defined functions. So here's onesolution.
Say you have these two tables:
TableA
------
KeyA text (10)
Data1 text (50)
TableB
------
KeyB long
DataB text (50)
First, create a VBA module in your Access db. Create a function like this:
Function ConvStr(aAs Long)
ConvStr = CStr(a)
End Function
Then you can use the function in a query to create what amounts to a new view of TableB, with the KeyB field converted to a string, like this:
QueryB
------
SELECT ConvStr([KeyB]) AS StrB, DataBFROM TableB;
Finally, create a second query to join the first query with TableA:
QueryA
------
SELECT TableA.KeyA, TableA.Data1, QueryB.DataB
FROM TableA INNER JOIN QueryB
ON TableA.KeyA = QueryB.StrB;
I hope this helps.
Steve Diamond
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending