views:

374

answers:

5

I modified one of the apps I made for russian market. Everything seemed to be fine, there was an issue when you enter data into database but it was solved by by setting page encoding to utf-8. So inserting and retrieving works fine. I ran into problem I just have no idea how to tackle. When I ran following query (simplified) in mssql query analyser (so no chance that it got messed up in the code), I get no results even thought there are a number of records matching: (version of mysql is 2005)

SELECT * FROM institutions WHERE city LIKE '%Москва%' ORDER BY address1

even if I modify it to be : SELECT * FROM institutions WHERE city='Москва' ORDER BY address1

or some other variation, it just isn't working. Question is why?

P.S. In case you can't see cyrillic letters after I submit this, it searches for Moscow as a city.

Anyone has solution or idea what to do?

+4  A: 

OK just found answer and it is lame :) a little. You need to add N in front of unicode string.

SELECT * FROM institutions WHERE city LIKE N'%Москва%' ORDER BY address1

I will leave this in case someone else get stuck with it.

Zeljko Dakic
+1  A: 

The N tells SQL Server that it is unicode not ascii

SQLMenace
A: 

Благодря! :)

A: 

I have exactly the same problem, but with a MySQL database - any ideas for this? The query with the inserted N' is also executed, but doesn't get any result. Everything is UTF-8, database, connection etc. If i echo the query in the script and copy & paste it into phpMyAdmin, the results are shown correctly.

A: 

And what if I need to search some string which I pass as a parameter to a stored procedure? For instance SELECT * FROM table WHERE column LIKE '%' + @cyrillicString + '%' where @cyrillicString is a parameter. Prefixing the first '%' with 'N' doesn't help...

HiveHicks