473,379 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Latin1_General_BIN comparing two char strings

My database is Latin1_General_BIN.
My table is called CUSTOMER.
One column in this table (descr_id) is defined as char(10).

When I query…

SELECT *
FROM CUSTOMER
WHERE descr_id = ‘ABCD’

Result set from above query is:
descr_id
ABCD

I get the same result back as I do when…
SELECT *
FROM CUSTOMER
WHERE descr_id = ‘ABCD ‘ (notice ABCD string has padded spaces).

Result set from above query is:
descr_id
ABCD

Does anyone know why this is the case? I would expect second query to
not to return anything.

Many thanks,
Igor
Jun 27 '08 #1
3 8312
SQL Server follows the ANSI standard padding rules for character strings,
which requires strings used in comparisons to be padded so that their
lengths match before comparing them.

http://support.microsoft.com/kb/316626

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #2
Thanks... lets look at the following example...
When running following query on SQL Server 2005 with
Latin1_General_BIN

SELECT *
FROM CUSTOMER
WHERE descr_id like ‘% ‘ (again, notice padded spaces after wild
card sign)

Result set from above query is:
descr_id
ABCD

...and same query on SQL Server 2000 with SQL_Latin1_General_CP850_BIN
returns nothing.

What is the difference here then? I presume difference is in collation
change, but can’t find any article that speaks about this issue. Any
help would be appreciated.

Thanks,
Igor
Jun 27 '08 #3
I just tested the following code on both SQL Server 2000 and SQL Server 2005
and it returns the same results (the matching row):

CREATE TABLE Foo (
keycol INT PRIMARY KEY,
datacol CHAR(10) COLLATE SQL_Latin1_General_CP850_BIN);

INSERT INTO Foo VALUES(1, 'ABCD');

SELECT datacol
FROM Foo
WHERE datacol LIKE '% ' COLLATE Latin1_General_BIN;

SELECT datacol
FROM Foo
WHERE datacol LIKE '% ';

Can you post example (DDL and sample data) to reproduce your results?

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Curtis Gilchrist | last post by:
I am required to read in records from a file and store them in descending order by an customer number, which is a c-style string of length 5. I am storing these records in a linked list. My...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
6
by: BrianJones | last post by:
I have a problem with the int strcmp(str1,str2) function: When I do: char *pass; char *passv; pass = getpass("Please enter....."); passv = getpass("Please verify.....");
88
by: William Krick | last post by:
I'm currently evaluating two implementations of a case insensitive string comparison function to replace the non-ANSI stricmp(). Both of the implementations below seem to work fine but I'm...
8
by: Frost | last post by:
Hi All, I am a newbie i have written a c program on unix for line by line comparison for two files now could some one help on how i could do word by word comparison in case both lines have the...
9
by: subramanian100in | last post by:
Suppose we have char *a = "test message" ; Consider the comparison if (a == "string") ..... Here "string" is an array of characters. So shouldn't the compiler
10
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
7
by: arnuld | last post by:
On Mon, 28 Apr 2008 07:25:53 +0000, Richard Heathfield wrote: Either you are not understanding me or I am not able to understand this <p_strcmpthing. This is your code:
5
by: =?Utf-8?B?UElFQkFMRA==?= | last post by:
Not really a C#-specific comment, more general .net observations. 1) A while back I found the need to determine whether or not a particular StringComparer was case-insensitive. The best way I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.