Solved

Select query results are incorrect - characters being ignored

Posted on 2008-10-28
3
312 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to create and populate a column map table 5 61
JQuery & Classic ASP 10 39
isNaN issue on the Table input text 2 41
When are cursors useful? 8 60
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

732 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