MS Access SQL - data type mismatch

noisepoet

Board Regular
Joined
Oct 19, 2006
Messages
82
Hi. While I've been writing Oracle SQL queries for a few years now, I'm relatively new to MS Access SQL. There are surprisingly few resources available online (via Google) for MS Access SQL. Given that, I'm having difficulty figuring out how to format a field which is text as a number (or vice versa). Do I use FORMAT()? Is it like this: FORMAT(FieldName,'General Number') ?

Thank you.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Yes, I'm using a SELECT statement.

While I'm able to go into Design View and change the data type that way, it's kind of a hassle. I'd prefer to do this via SQL.
 
Upvote 0
Can you show the SQL that's giving you a type mismatch?
 
Upvote 0
It may not be very helpful. It's literally: AND A.FieldName = B.FieldName. The issue is that Table A has the value expressed as numeric, whereas Table B has the same value formatted as text.
 
Upvote 0
format can work here, but it would always return text (so you would want to format the number and compare to the text value).

Also in MSAccess the C functions (CInt, CDbl, CStr, etc.) will cast values to other datatypes, so probably good is to convert the text to number also (except would probably blow up if you try to convert a non-numeric text string to a number so beware).

Code:
where format(A.FieldName1,"#") = B.FieldName2
or
Code:
where A.FieldName1 = CInt(B.FieldName2)
 
Last edited:
Upvote 0
Actually I should have suggested CLng - cast as long integer

Code:
where A.FieldName1 = CLng(B.FieldName2)

MSAccess ints are what most other systems call short ints - limited to values between -32768 to 32767. Most Access number fields are Long Integers or Doubles.
 
Last edited:
Upvote 0
Yes, I'm using a SELECT statement.

While I'm able to go into Design View and change the data type that way, it's kind of a hassle. I'd prefer to do this via SQL.

that was sql

its a simple selct statement

select * from my_table where my_table.FieldName = cdbl ( a_text_value )

are you sure you've done oracle for years ?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,297
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top