473,403 Members | 2,354 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,403 software developers and data experts.

Unicode chars with like query statement problem

I have a Users table which contains a nvarchar column LastName. The
first query below returns me all the records with LastName containing
"opez" or "ópez" in them. But the second query returns only records
with "lopez" in the lastname and not records that contain "lópez".
Can anyone please tell me what is it that i am missing?

SELECT *
FROM tbUsers
WHERE (LastName LIKE '%[oó]pez%')

SELECT *
FROM tbUsers
WHERE (LastName like '%l[oó]pez%')

thanks

Jul 23 '05 #1
4 7072
Kavitha (ka************@gmail.com) writes:
I have a Users table which contains a nvarchar column LastName. The
first query below returns me all the records with LastName containing
"opez" or "ópez" in them. But the second query returns only records
with "lopez" in the lastname and not records that contain "lópez".
Can anyone please tell me what is it that i am missing?

SELECT *
FROM tbUsers
WHERE (LastName LIKE '%[oó]pez%')

SELECT *
FROM tbUsers
WHERE (LastName like '%l[oó]pez%')


I was not able to repeat this. If you can produce a script similar
to the one below that demonstrates the problem, it's a little easier
to get an idea of what is going on. Don't forget to include the collation
of the column.

CREATE TABLE tbl
(lastname nvarchar(30) COLLATE Finnish_Swedish_BIN NOT NULL)
go
INSERT tbl (lastname) VALUES ('Mopez')
INSERT tbl (lastname) VALUES ('Mópez')
INSERT tbl (lastname) VALUES ('lopez de la serra')
INSERT tbl (lastname) VALUES ('x lópez')
go
SELECT * FROM tbl WHERE lastname LIKE '%[oó]pez%'
SELECT * FROM tbl WHERE lastname LIKE '%l[oó]pez%'
SELECT * FROM tbl WHERE lastname LIKE N'%[oó]pez%'
SELECT * FROM tbl WHERE lastname LIKE N'%l[oó]pez%'
go
drop table tbl

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
Thanks for the response. Here is some more information. I am using
utf-16 encoding and so when i store a "latin small letter o with
acute", it gets stored as "ó" which looks like a capital letter A
with tilde and a superscript 3.

After inserting the following row into the tbl Table, the first select
statement below works while the second one does not.

INSERT tbl (lastname) VALUES ('lópez')

SELECT * FROM tbl WHERE lastname LIKE N'%[oóó]pez%'

SELECT * FROM tbl WHERE lastname LIKE N'%l[oóó]pez%'

Jul 23 '05 #3
Am 28 Jun 2005 08:22:51 -0700 schrieb Kavitha:
I have a Users table which contains a nvarchar column LastName. The
first query below returns me all the records with LastName containing
"opez" or "ópez" in them. But the second query returns only records
with "lopez" in the lastname and not records that contain "lópez".
Can anyone please tell me what is it that i am missing?

SELECT *
FROM tbUsers
WHERE (LastName LIKE '%[oó]pez%')

SELECT *
FROM tbUsers
WHERE (LastName like '%l[oó]pez%')

thanks


try this:
SELECT * FROM tbUsers
WHERE (LastName like N'%l[oó]pez%')

I think it needs the "N" in front of the string.

bye,
Helmut
Jul 23 '05 #4
Kavitha (ka************@gmail.com) writes:
Thanks for the response. Here is some more information. I am using
utf-16 encoding and so when i store a "latin small letter o with
acute", it gets stored as "ó" which looks like a capital letter A
with tilde and a superscript 3.


Apparently, you are using UTF-8 somewhere, and you end up with UTF-8
in a database that works with UTF-16.

Also see my reply to dBlue. (And if you are the same person, please
stick to one alias, and one thread.)

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #5

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

Similar topics

0
by: Stormblade | last post by:
Hey all, I have an existing JSP web application which retrieved data from a SQLServer database and displayed it. The data contained Unicode chars. This worked fine. I changed databases/JDBC...
2
by: Silvio Lopes de Oliveira | last post by:
Hello, I use Unicode in my program to enter data in Chinese into a nvarchar field. When inserting or updating records, my application does not use Unicode escape sequences but rather the Unicode...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
7
by: Robert | last post by:
Hello, I'm using Pythonwin and py2.3 (py2.4). I did not come clear with this: I want to use win32-fuctions like win32ui.MessageBox, listctrl.InsertItem ..... to get unicode strings on the...
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
5
by: Nadav Popplewell | last post by:
Hi everybody, I've got a web application where I need to join several strings, some of which are read from a dbase and display then IN the order they are joined. I.E. I want to display "Hello...
9
by: Jim | last post by:
Hello, I'm trying to write exception-handling code that is OK in the presence of unicode error messages. I seem to have gotten all mixed up and I'd appreciate any un-mixing that anyone can...
7
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
1
by: Mudcat | last post by:
In short what I'm trying to do is read a document using an xml parser and then upload that data back into a database. I've got the code more or less completed using xml.etree.ElementTree for the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.