Solved

Select query results are incorrect - characters being ignored

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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