?
Solved

Select query results are incorrect - characters being ignored

Posted on 2008-10-28
3
Medium Priority
?
323 Views
Last Modified: 2010-07-27
I have been fighting with this query for some time, it seems that the select is ignoring the last 4 characters in the statement below. Instead of returning the matching record it returns the first record beginning with 1234567890098765

SELECT * from  table where table.sim = 12345678900987654321

When I test the same logic on another database field with a smaller (in length) variable, the information is correct - so I know my syntax is correct.

So the question is - How can I perform a select on a field where its length is 20 characters?

Thanks in advance.
0
Comment
Question by:wfluisi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22824788
If it's a char field (or varchar) then you need to wrap your value in quotes.  This will prevent SQL from doing an implicit conversion and it will be using the (var)char data type you are using.  It also then won't trim any leading 0s.

SELECT * from  table where table.sim = '12345678900987654321'
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22824847
is the field CHAR, by any chance?
0
 

Author Closing Comment

by:wfluisi
ID: 31510877
Thanks BrandonGladerisi - you nailed it on the head!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question