473,699 Members | 2,181 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 7084
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
1301
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, however, the query returns data with all the unicode chars converted to question marks. I have...
2
7475
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 both in my app and through SQL Server Enterprise
4
6066
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 python minidom and everything concerning
7
4201
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 possible at the console with normal print-s to stdout (on varying platforms, different
40
3227
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 language (and on the encoding) might contain characters that require more that a single byte.
5
1299
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 the USERNAME can be either hebrew or english or mixed. Because of the BIDI algorithm if the string...
9
2935
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
4019
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
3856
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 characters and then encoding everything to ascii. That allowed me to build the application and debug...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8945
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8902
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7787
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5889
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4392
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3075
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
2
2366
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.