Home All Groups Group Topic Archive Search About

compare '002' and '00²'

Author
29 Dec 2005 1:39 PM
Gene Vangampelaere
does anyone knows why '002' = '00²' in sqlserver 2000 ?


create table Test2 (veldnaam varchar(10),veldnaam2 varchar(10))
go
insert into test2 values ('002','00²')
go
select * from Test2 where veldnaam=veldnaam2


I did not expect to find a record !



Gene

Author
29 Dec 2005 1:46 PM
Uri Dimant
Gene
I've got  nothing.
What is the version of SQL Server?



Show quote
"Gene Vangampelaere" <gene.vangampelaere.remove.t***@infohos.remove.this.be>
wrote in message news:urYhZ1HDGHA.984@tk2msftngp13.phx.gbl...
> does anyone knows why '002' = '00²' in sqlserver 2000 ?
>
>
> create table Test2 (veldnaam varchar(10),veldnaam2 varchar(10))
> go
> insert into test2 values ('002','00²')
> go
> select * from Test2 where veldnaam=veldnaam2
>
>
> I did not expect to find a record !
>
>
>
> Gene
>
>
>
Author
29 Dec 2005 1:53 PM
Steven Wilmot
Show quote
"Uri Dimant" <u***@iscar.co.il> wrote in message
news:em1lF5HDGHA.412@TK2MSFTNGP15.phx.gbl...
> Gene
> I've got  nothing.
> What is the version of SQL Server?
>
>
>
> "Gene Vangampelaere"
> <gene.vangampelaere.remove.t***@infohos.remove.this.be> wrote in message
> news:urYhZ1HDGHA.984@tk2msftngp13.phx.gbl...
>> does anyone knows why '002' = '00²' in sqlserver 2000 ?
>>
>>
>> create table Test2 (veldnaam varchar(10),veldnaam2 varchar(10))
>> go
>> insert into test2 values ('002','00²')
>> go
>> select * from Test2 where veldnaam=veldnaam2
>>
>>
>> I did not expect to find a record !
>>

Could you confirm the exact character codes in those fields

e.g.:
   select convert(varbinary(25),veldnaam),convert(varbinary(25),veldnaam2)
from Test2 where veldnaam=veldnaam2

Also, the collation settings
  select databasepropertyex(db_name(),'Collation')

The collation will affect comparators like '=', '>', etc.
Author
29 Dec 2005 1:49 PM
David Portas
Gene Vangampelaere wrote:
Show quote
> does anyone knows why '002' = '00²' in sqlserver 2000 ?
>
>
> create table Test2 (veldnaam varchar(10),veldnaam2 varchar(10))
> go
> insert into test2 values ('002','00²')
> go
> select * from Test2 where veldnaam=veldnaam2
>
>
> I did not expect to find a record !
>
>
>
> Gene

That depends what collation you use. You didn't specify the collation
explicity so the default for your database will be used.

With this CREATE TABLE statement those values will be returned as
equal:
create table Test2 (veldnaam varchar(10) COLLATE Latin1_General_CI_AS,
veldnaam2 varchar(10) COLLATE Latin1_General_CI_AS)

With this one they won't:
create table Test2 (veldnaam varchar(10) COLLATE Latin1_General_BIN,
veldnaam2 varchar(10) COLLATE Latin1_General_BIN)

You can also specify the collation in your query:

SELECT *
FROM Test2
WHERE veldnaam=veldnaam2 COLLATE Latin1_General_BIN ;

--
David Portas
SQL Server MVP
--
Author
29 Dec 2005 2:10 PM
Gene Vangampelaere
thx !

It was a collation problem !



"David Portas" <REMOVE_BEFORE_REPLYING_dpor***@acm.org> schreef in bericht
news:1135864153.135650.46570@g49g2000cwa.googlegroups.com...
Gene Vangampelaere wrote:
Show quote
> does anyone knows why '002' = '00²' in sqlserver 2000 ?
>
>
> create table Test2 (veldnaam varchar(10),veldnaam2 varchar(10))
> go
> insert into test2 values ('002','00²')
> go
> select * from Test2 where veldnaam=veldnaam2
>
>
> I did not expect to find a record !
>
>
>
> Gene

That depends what collation you use. You didn't specify the collation
explicity so the default for your database will be used.

With this CREATE TABLE statement those values will be returned as
equal:
create table Test2 (veldnaam varchar(10) COLLATE Latin1_General_CI_AS,
veldnaam2 varchar(10) COLLATE Latin1_General_CI_AS)

With this one they won't:
create table Test2 (veldnaam varchar(10) COLLATE Latin1_General_BIN,
veldnaam2 varchar(10) COLLATE Latin1_General_BIN)

You can also specify the collation in your query:

SELECT *
FROM Test2
WHERE veldnaam=veldnaam2 COLLATE Latin1_General_BIN ;

--
David Portas
SQL Server MVP
--
Author
29 Dec 2005 1:55 PM
Roji. P. Thomas
I am not seeing any record.

Whats your version/SP Level?


--
Roji. P. Thomas
Net Asset Management
http://toponewithties.blogspot.com


Show quote
"Gene Vangampelaere" <gene.vangampelaere.remove.t***@infohos.remove.this.be>
wrote in message news:urYhZ1HDGHA.984@tk2msftngp13.phx.gbl...
> does anyone knows why '002' = '00²' in sqlserver 2000 ?
>
>
> create table Test2 (veldnaam varchar(10),veldnaam2 varchar(10))
> go
> insert into test2 values ('002','00²')
> go
> select * from Test2 where veldnaam=veldnaam2
>
>
> I did not expect to find a record !
>
>
>
> Gene
>
>
>
Author
29 Dec 2005 2:05 PM
Aaron Bertrand [SQL Server MVP]
Well, they seem to have the same ASCII code in my collation:

SELECT ASCII('002'), ASCII('00²')
------------- --------------
48        48

The position of the digit on the line is a formatting one, I think... I
don't know that SQL Server will be able to tell them apart.


Show quote
"Gene Vangampelaere" <gene.vangampelaere.remove.t***@infohos.remove.this.be>
wrote in message news:urYhZ1HDGHA.984@tk2msftngp13.phx.gbl...
> does anyone knows why '002' = '00²' in sqlserver 2000 ?
>
>
> create table Test2 (veldnaam varchar(10),veldnaam2 varchar(10))
> go
> insert into test2 values ('002','00²')
> go
> select * from Test2 where veldnaam=veldnaam2
>
>
> I did not expect to find a record !
>
>
>
> Gene
>
>
>
Author
29 Dec 2005 2:11 PM
Aaron Bertrand [SQL Server MVP]
> The position of the digit on the line is a formatting one, I think... I
> don't know that SQL Server will be able to tell them apart.

....in certain collations.  SQL Server does in fact store the varbinary
representation, so:

SELECT ASCII('002'), CONVERT(VARBINARY(12), '002')
SELECT ASCII('00²'), CONVERT(VARBINARY(12), '00²')

----------- --------------------------
48          0x303032
----------- --------------------------
48          0x3030FD

So you can treat this like a case sensitive query, and use explicit
collation hints or varbinary conversions in the query, or change your
collation to binary (this is a bit more drastic).  For some related
information see http://www.aspfaq.com/2152
Author
29 Dec 2005 2:15 PM
SQL
SELECT ASCII('002'), ASCII('00²')  this will only look at the 0 you
will have to loop thru it
Check it out SELECT ASCII('002') , ASCII('00²') , ASCII('02'),
ASCII('0²') ,ASCII('0'), ASCII('0') all 48
How about this  SELECT ASCII('2'), ASCII('²')  these are not the same
(50 and 178)


http://sqlservercode.blogspot.com/
Author
29 Dec 2005 2:29 PM
Aaron Bertrand [SQL Server MVP]
Yep, you're right, sorry.  See my follow-on...


"SQL" <denis.g***@gmail.com> wrote in message
news:1135865754.519678.66870@g43g2000cwa.googlegroups.com...
SELECT ASCII('002'), ASCII('00²')  this will only look at the 0 you
will have to loop thru it
Check it out SELECT ASCII('002') , ASCII('00²') , ASCII('02'),
ASCII('0²') ,ASCII('0'), ASCII('0') all 48
How about this  SELECT ASCII('2'), ASCII('²')  these are not the same
(50 and 178)


http://sqlservercode.blogspot.com/

AddThis Social Bookmark Button