Samarth Agarwal
Samarth Agarwal

Reputation: 2134

SQL data not retrieved in Unicode Hindi

I am developing a web app in ASP.NET with C#. I am saving data in SQL tables as Unicode character as given by Google Transliteration. I am supposed to use Hindi. I have no issues regarding adding data. But when I use "SELECT" statements, no data is retrieved from the database tables in any case.

My Query is as follows:

SELECT        uid, family_head, member_name, house_no, address, f_h_name, gender, caste, dob, occupation, literacy, end_date
FROM            family
WHERE        (member_name = 'समर्थ अग्रवाल')

It return null.

Upvotes: 2

Views: 3109

Answers (1)

Oded
Oded

Reputation: 498972

Change the string to start with N to signify it is a Unicode string:

SELECT        uid, family_head, member_name, house_no, address, f_h_name, gender, caste, dob, occupation, literacy, end_date
FROM            family
WHERE        (member_name = N'समर्थ अग्रवाल')

Otherwise, the string will not be a Unicode string and the query will return no results.

See Constants (Transact-SQL) on MSDN:

Unicode strings

Unicode strings have a format similar to character strings but are preceded by an N identifier (N stands for National Language in the SQL-92 standard). The N prefix must be uppercase. For example, 'Michél' is a character constant while N'Michél' is a Unicode constant. Unicode constants are interpreted as Unicode data, and are not evaluated by using a code page.

Upvotes: 5

Related Questions