473,657 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL 2000 and UTF-16 encoding

Hi all,

I have an issue on querying against UTF-16 encoded characters in
SQL2000 database: For example the "López" is saved into database as
"López" (due to the UTF-16 encoding); somehow, when I query data
with conditions of "like 'lop%'" or "like 'Lóp%'", the row of López
would not return.

NOTE: the accent insensitive collation can not help in this case.

Thank you,

Albion(052X)

Jul 23 '05 #1
8 6052
[posted and mailed, please reply in news]

dBlue (zk*****@hotmai l.com) writes:
I have an issue on querying against UTF-16 encoded characters in
SQL2000 database: For example the "López" is saved into database as
"López" (due to the UTF-16 encoding); somehow, when I query data
with conditions of "like 'lop%'" or "like 'Lóp%'", the row of López
would not return.

NOTE: the accent insensitive collation can not help in this case.


I answered a very similar question yesterday, and while the username
and e-mail address, I would assume that you are the same person. I cannot
do much more but repeat my answer from yesterday:

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****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
Thank you Erland for the reply, unfortunatly, the problem remains.

I understand your example well, and it is exactly the sql query we are
using now. The problem is not at the accent. The query does not
return me the data row, because the character is save as "López" in
the database, and the [oó] does not help on it.

BTW, the accent insensitive insensitive does not help either.

Thank you,

Albion(052X)

Jul 23 '05 #3
Hi,

Please try the script below. It is a bit weired to me.

CREATE TABLE tbl
(lastname nvarchar(30) NOT NULL)
go
INSERT tbl (lastname) VALUES ('MópeX')
INSERT tbl (lastname) VALUES ('MópeY')
INSERT tbl (lastname) VALUES ('MopeZ')
go

SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M%[óo]pe%'
GO

Drop table tbl

The frist two select statement does not return same result as they
suppose to. Any idea?

Thank you,

Albion(052X)

Jul 23 '05 #4
BYTW, I found an very instereting stuff. Please the script below,

The first 1 and 2 select statement should return same result, but they
do not; and only difference between them is 1 statement does not have
the M character inside the like statement.
CREATE TABLE tbl
(lastname nvarchar(30) NOT NULL)
go
INSERT tbl (lastname) VALUES ('MópeX')
INSERT tbl (lastname) VALUES ('MópeY')
INSERT tbl (lastname) VALUES ('MopeZ')
go
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M%[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%[o]pe%'
GO

drop table tbl
Thank you,

Albion(052X)

Jul 23 '05 #5
| "dBlue" <zk*****@hotmai l.com> schrieb im Newsbeitrag
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
|Hi all,
|
|I have an issue on querying against UTF-16 encoded characters in
|SQL2000 database: For example the "López" is saved into database as
|"López" (due to the UTF-16 encoding);

This is not a UTF-16 representation but UTF-8.

--

Vincent Wehren


|somehow, when I query data
|with conditions of "like 'lop%'" or "like 'Lóp%'", the row of López
|would not return.

|NOTE: the accent insensitive collation can not help in this case.

|Thank you,

|Albion(052X)
Jul 23 '05 #6
dBlue (zk*****@hotmai l.com) writes:
BYTW, I found an very instereting stuff. Please the script below,

The first 1 and 2 select statement should return same result, but they
do not; and only difference between them is 1 statement does not have
the M character inside the like statement.
CREATE TABLE tbl
(lastname nvarchar(30) NOT NULL)
go
INSERT tbl (lastname) VALUES ('MópeX')
INSERT tbl (lastname) VALUES ('MópeY')
INSERT tbl (lastname) VALUES ('MopeZ')
go
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M%[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%[o]pe%'
GO

drop table tbl


But "MópeX" is not the same as "MópeX". The first string has six
characters, the second has five. Both strings match N'%[óo]pe%' -
that is first any number of characters and then exactly one of
"Ã", "³" or "o" and then "pe" followed by any number of chars.

On the other hand, the string N'%M[óo]pe%', you say that there
should be an M and then exactly one of "Ã", "³" or "o" and then "pe",
which there is in the six-char string.

OK, so that "MòpeZ" is really a representation of "MópeX", to whit
the bit pattern that you have in UTF-8, but stored in a string which
is supposed to hold UTF_16 values, and then it goes downhill from
there.

So I guess you really problem is why you have UTF-8 encodings in the
wrong place. When I saw your first posting, I assumed that the mangled
UTF-8 came from the news posting itself, but it appears now that it
comes from the database.

--
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 #7
Hi,

Thank you for the reply.

It seems like it is the problem on querying for the 'MópeX' from the
SQL, but getting correct 'MópeX', rather than getting the 'MópeX'.
Is that right?

The following is the function we use to do the decoding for the
URLstring. I can add the WideCharToMulti Byte and MultiByteToWide Char
to get correct data. But is there a more efficient way?

str = Replace(str, "+", " ")

i = 0
Do
i = InStr(i + 1, str, "%")
If i = 0 Then
Exit Do
End If
var_char = Chr(CStr("&H" + Mid(str, i + 1, 2)))
If Err.Number = 0 Then
str = Mid(str, 1, i - 1) _
& var_char _
& Mid(str, i + 3)
End If
Loop

thanks again.
Erland Sommarskog wrote:
dBlue (zk*****@hotmai l.com) writes:
BYTW, I found an very instereting stuff. Please the script below,

The first 1 and 2 select statement should return same result, but they
do not; and only difference between them is 1 statement does not have
the M character inside the like statement.
CREATE TABLE tbl
(lastname nvarchar(30) NOT NULL)
go
INSERT tbl (lastname) VALUES ('MópeX')
INSERT tbl (lastname) VALUES ('MópeY')
INSERT tbl (lastname) VALUES ('MopeZ')
go
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%M%[óo]pe%'
SELECT * FROM tbl WHERE lastname Collate
SQL_Latin1_Gene ral_CP1_CI_AI LIKE N'%[o]pe%'
GO

drop table tbl


But "MópeX" is not the same as "MópeX". The first string has six
characters, the second has five. Both strings match N'%[óo]pe%' -
that is first any number of characters and then exactly one of
"Ã", "³" or "o" and then "pe" followed by any number of chars.

On the other hand, the string N'%M[óo]pe%', you say that there
should be an M and then exactly one of "Ã", "³" or "o" and then "pe",
which there is in the six-char string.

OK, so that "MòpeZ" is really a representation of "MópeX", to whit
the bit pattern that you have in UTF-8, but stored in a string which
is supposed to hold UTF_16 values, and then it goes downhill from
there.

So I guess you really problem is why you have UTF-8 encodings in the
wrong place. When I saw your first posting, I assumed that the mangled
UTF-8 came from the news posting itself, but it appears now that it
comes from the database.

--
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 #8
dBlue (zk*****@hotmai l.com) writes:
It seems like it is the problem on querying for the 'MópeX' from the
SQL, but getting correct 'MópeX', rather than getting the 'MópeX'.
Is that right?
The problem is that you have garbage in your database, yes.
The following is the function we use to do the decoding for the
URLstring. I can add the WideCharToMulti Byte and MultiByteToWide Char
to get correct data. But is there a more efficient way?

str = Replace(str, "+", " ")

i = 0
Do
i = InStr(i + 1, str, "%")
If i = 0 Then
Exit Do
End If
var_char = Chr(CStr("&H" + Mid(str, i + 1, 2)))
If Err.Number = 0 Then
str = Mid(str, 1, i - 1) _
& var_char _
& Mid(str, i + 3)
End If
Loop


I don't know what URL string you have, and I am not an expert on how
to write effecient VB code.

I have however used WideCharToMulti Byte and MultiByteToWide Char (from
C++) to convert between UTF-8 and UTF-16, and found them to work well.
--
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 #9

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

Similar topics

16
22467
by: Michael Walton | last post by:
I am trying to write some code that inserts or updates a text field in my SQL Server 2000 database. The SQL statement is created using a submit from a form, and the text is coming from a <textarea>, and therefore being placed into the SQL statement via a Request("field"). However, due to limitations in SQL Server 2000 and text fields, I can not use a simple Update or Insert command with text over 8000 bytes. Does anybody have any...
2
15184
by: James Allan | last post by:
Hello -- I'm trying to get SQL Server 2000 on a Windows 2000 Server to be able to query an Active Directory. We've got two domain servers one Win2000 and one Win2003. However, I'm having problems: I've run the following query to setup the linked server: sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'
3
3325
by: Michael | last post by:
Is there a GUI to do like drag and drop and very powerful , but not DOT NET dependant. I have found some programs that are GUI rich in scripting for SQL 2000 and even MY SQL, but they are dot Nut,net dependant. michael
12
10017
by: M Wells | last post by:
Hi All, I have a table that holds pregenerated member IDs. This table is used to assign an available member id to web site visitors who choose to register with the site So, conceptually the process has been, from the site (in ASP), to: - select the top record from the members table where the assigned flag
2
1173
by: Graham Carr | last post by:
Hi, My client has the need to upgrade to Windows 2000 Server from NT4 but are concerned about whether there existing custom code (ASP,VB6,MTS, etc) will work correctly once migrated. Does anyone know where I might be able to find information relating to what functionality has been deprecated in Windows 2000 Server since NT4 (I know CDONTS is one of them).
3
1931
by: Les Juby | last post by:
Getting really stumped here..... Using Classic.ASP and after an editing page has been completed I need to write the values back to an Access 2000 database. But I'm battling with a checkbox resultwhich has to be stored in aYes/No field. I'm testing the variable no_mail to see if it returns "on" in ASP which means the checkbox is ticked. I then load a variable called sql_val_no_mail with the text that the SCP statement will use to...
3
3145
by: Mark | last post by:
Any Visual C++ source code available for disabling the following keys in windows 2000. Alt + Ctrl + Del Ctrl + Esc Windows Key to Remove task bar Function keys (or Alt + Function keys or Ctrl + function keys) disabling the Right mouse
7
1216
by: Axel Dahmen | last post by:
I've just installed Windows 2000 Service Pack 4 (SP4) on my Windows 2000 Server. Now I can't debug anymore! I'm using Visual Studio 7.0 (2002), ..NET Framework 1.0. The error message I get is (translated): "Error running the project. Unable to start debugging on the web server. Critical failure. Would you like to disable future attempts to debug ASP.NET pages for this project?" What can I do?? Please help, I'm desperate! TIA, Axel...
1
2063
by: Ohaya | last post by:
Hi, We are running a website on a Windows 2000 Advanced Server machine with 4 CPUs and Hyperthreading enabled (i.e., 8 virtual processors). The web server is IIS5. Our application uses ASP.net, and we originally were testing the application on a test system with a single CPU and no hyperthreading. When we moved the application to the production machine (the one with 4
5
2054
by: znubbe | last post by:
Hi, I hope anyone can help me with this problem. I have a field of image type in a SQL 2000 database. I'm using this code to insert a document: Dim conn Dim rs Dim oStream
0
8403
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8509
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
8610
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...
1
6174
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
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
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.