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
Solved

Select query results are incorrect - characters being ignored

Posted on 2008-10-28
3
303 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
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 125 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
awk and Pythagoras? 5 19
Html value of radio 14 27
SQL group by query to return records with highest value 6 24
Accessing variables in MySQL query 4 28
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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