Link to home
Start Free TrialLog in
Avatar of Lalibela
Lalibela

asked on

unicode comparison

Hello,

I want to compare two an a string which is a unicode in where clause of SQL, like SELECT * FROM tblName where fieldName=N'unicodeencodedString'. The trouble is it always return all the records. Can somebody help me on this?

Lalibela,

:14:15
Avatar of ill
ill
Flag of Slovakia image

how does N'unicodeencodedString' you are passing looks like?
Please post your code
fieldname must be defined as an NCHAR or NVARCHAR, otherwise you'll need to convert the fieldname to unicode
Avatar of Lalibela
Lalibela

ASKER

Hello,

I have defined field name with type NVARCHAR and the data is passed from jsp page encoded with UTF-8. I want to use it for checking user privilege. Here is the SQL:

SELECT * FROM tblUser where userName=N'ላሊበላ'; that is all.


Lalibela,

:14:15



Is the username data URI Encoded in your table?

The SQL engine doesn't know how to decode the string, so that could be the problem.  It would be an interesting feature to add, but it's not currently there.  However, if you are storing them encoded, it should work, although it would then be more difficult to produce hman readable reports.  If you're not sure what I'm asking, reply with a sample row of the username field.

If that is the problem, then you should use something like the unescape() method in javascript to convert the encoded string to the original text representation of the username.
Hello,

I have stored the unicode character and retrive it correctly. I use JDBC-ODBC bridge.The problem is with searching. I discovered this,when I change the collation to binary 850_CP it works correctly. Can anybody tell me the default collation for unicode characters other than the ones provided by SQL SERVER? like for languages Ethiopic... I think the collation is the problem.


Thanks,

Lalibela,
:14:15
Avatar of Vadim Rapp
use LIKE instead of = . LIKE is UNICODE-aware. = is not. I.e.

SELECT * FROM tblName where fieldName LIKE N'unicodeencodedString'
Hello,

I have used like but it does not work. I change the collation and it works fine with me.

Thanks,

:14:15
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial