October 18, 2005 at 11:30 am
I am trying to do a search for special characters using like
When I run my query
select * from tblXMLOrderLotShipping
where shipto like '%Œ%'
to search for Œ
None of the results returned contain Œ.
Can anyone explain why this is haappening and how to get around it?
October 18, 2005 at 11:47 am
Couple of questions:
What is the data type of "shipto"?
What is the Collation of your database ?
 * Noel
October 18, 2005 at 12:20 pm
I used the ASCII function to get the ascii code for Œ, which is 140 so write a function like so;
select * from tblXMLOrderLotShipping
where charindex(char(140),shipto) > 0
hope that helps.
![]()
October 18, 2005 at 12:53 pm
No the Charindex returns the same result set. The one thing that the results have in common in the characters O and E. Strange because the look the same. The Colation on this database is SQL_Latin1_General_CP1_CI_AS.
What in the heck is Œ any way?
October 18, 2005 at 12:56 pm
Oh and the data type is nvarchar.
October 18, 2005 at 1:01 pm
"Shipto" DATA TYPE, Please ![]()
 * Noel
October 18, 2005 at 1:18 pm
The shipto datatype is nvarchar
October 18, 2005 at 1:18 pm
The shipto datatype is nvarchar
October 18, 2005 at 1:25 pm
maybe this will help you
DECLARE @T TABLE (shipto nvarchar(50))
insert into @T select N'aaaaa'+nchar(140)+N'bbbbbbbb'
insert into @T select N'bbbbbb'+nchar(140)+N'bbbbbbbb'
insert into @T select N'aaaaa'+N'aaaaaaa'
select * from @T
where shipto like N'%'+nchar(140)+N'%'
select * from @T
where shipto like N'%'+N'Œ'+N'%'
print unicode(N'Œ')
print ascii('Œ')
Vasc
October 18, 2005 at 3:38 pm
Sorry I coudn't get back earlier.
To make the long story short it is the conversion to Unicode what messes up the data because 'Œ' is not part of the unicode standard ![]()
and because the comparison with LIKE , IN CHARINDEX, etc will try to "implicitly" convert to a unicode expression (data type nvarchar) you get the unexpected results.
a workaround maybe
select * from tblXMLOrderLotShipping
where cast(shipto as varchar(50)) like '%Œ%
I know is ugly but I could not prevent unicode converssion 
 You could also perform binary comparison to get around that issue ![]()
hth
 * Noel
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply