473,563 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7078
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 ('Mpez')
INSERT tbl (lastname) VALUES ('lopez de la serra')
INSERT tbl (lastname) VALUES ('x lpez')
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****@sommarsk og.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****@sommarsk og.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
1295
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 drivers over to MySQL. I've set the database to use utf8 and the tables as well. I've viewed the data in the table and it contains unicode just fine,...
2
7470
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 characters themselves. Thus, my app may have SQL statements like: UPDATE table SET field1 = '<some string in Chinese>'; The syntax above works...
4
6050
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 script that grabs some web pages from the web, regex parse the data and stores it localy to xml file for further use.. at first i had no problem using...
7
4192
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 screen - best results according to the platform/language settings (mainly XP Home, W2K, ...). Also unicode strings should be displayed as nice as...
40
3169
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, including asian languages (chinese, japanese, korean, etc). First of all, strings will be passed to my class methods, some of which based on the...
5
1297
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 {USERNAME}, How are you doing?" ({USERNAME} is read from dbase). Now the problem is that the strings around the {USERNAME} should be in hebrew, and...
9
2927
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 give me. I'm used to writing code like this.
7
4013
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
3850
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 parser and dbi/ odbc for my db connection. To fix problems with unicode I built a work-around by mapping unicode characters to equivalent ascii...
0
7580
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.