Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing Text to Autonum in SQL

Status
Not open for further replies.

sparkus

Technical User
Nov 11, 2004
6
US
Hey,

I'm trying to help someone out. They have a complicated table and decided to store autonumbers in a text field and attempt to join them up in SQL, but everytime I try to join I get a type mismatch error.....

I can only do it via Jet Sql....

Thanks!!!
 
Take a look at the Int or Val function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Can you do that in the SQL statement????
 
Yes, even in the JOIN clause:
... FROM Table1 INNER JOIN Table2 ON Int(Table1.txtField) = Table2.AutoField ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I still get a type mismatch....

SELECT test.*, links.*, test.primarykeyme
FROM links, test
WHERE(test.primarykeyme)=Int(links.encrypting_device);
 
What are the data type of test.primarykeyme and links.encrypting_device ?
Some sample values may help.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Crud,

He stuck some non-integer values into the textfield.....is there any way to convert the autonum to a text so I can get around this?

Thank you very much for your help!!!!!
 
Something like this ?
WHERE links.encrypting_device Like '*' & test.primarykeyme & '*';

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Bloody Genius!!!!

Thank you so much!!!!

and to think I spent 5 hours before I came here.....

Thanks again!
 
WHERE links.encrypting_device Like '*' & test.primarykeyme & '*'

This is a little risky. If you have Text values that are substrings of other Text values (e.g. 111 and 11), they will both match an Autonum of 11.

You could use CStr(AutoNum) instead.

John
 
JonFer,

Thank you very much, you helped save my butt!

I was getting a lot of primary key mismatches.

Thanks again!!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top