views:

356

answers:

3

A Microsoft Access implementation is throwing a type mismatch error while trying to execute a macro that opens up some queries. Most of the tables are linked to a SQL Server and I need to join two of the tables together that have different datatypes.

Table A:
REFERENCE TEXT

Table B:
REFNO NUMBER

I would ordinarily want to correct the issue on the SQL Server side, but there are multiple apps hitting the same database and it would take a considerable amount of time to test all of them. Furthermore, we are in the process of completely rewriting this application and any work I do today is completely throw-away...

If there is a way to make this join possible in access, I would save all kinds of time...

A: 

What is the datatype for each of the column, you mentioned?

If you want to compare it stringwise, you could do Cstr(myNumericColumn) = myStringColumn.
OR to compare it in numeric mode, do CLng(myStringColumn) = myNumericColumn.

shahkalpesh
its above, tableA has a text column while tableB has a integer column.
RSolberg
You can use either of the above, depending on how you wish to compare.
shahkalpesh
I don't believe that works in the context of a join
RSolberg
I dont know what you mean by that. Could you explain as to why using Cstr or Clng doesn't help in your case?
shahkalpesh
+3  A: 

Within Access you could use the CLng (or Cint) function to convert the Table A's REFERENCE values from text to number.

I would prefer to create a view of Table A in SQL Server to transform the field's data type before Access gets the data. You shouldn't need to test the view against your other existing apps. When your re-write make the view no longer useful, just discard it.

HansUp
I was able to accomplish this by creating a view on the SQL DB and then brought that into Access and replaced the table with the view for the queries. Thanks for the quick suggestion.
RSolberg
+1  A: 

You can do the comparison in the criteria.

SELECT [REFERENCE], [REFNO]
FROM [Table a], [Table b]
WHERE [REFERENCE]=cstr(nz([REFNO],""))

You can also do a passthrough - a query in access that executes on the sql server and returns only the data.

SELECT [REFERENCE], [REFNO]
FROM [Table a], [Table b]
WHERE [REFERENCE]=cast([REFNO] as varchar(25))

HTH

Praesagus