0

With NVARCHAR data type, I store my local language text in a column. I face a problem how to query that value from the database.

  • ዜናገብርኤልስ is stored value.

I wrote SQL like this

select DivisionName 
from t_Et_Divisions 
where DivisionName = 'ዜናገብርኤልስ'

select unicode (DivisionName) 
from t_Et_Divisions 
where DivisionName = 'ዜናገብርኤልስ'

The above didn't work. Does anyone have any ideas how to fix it?

Thanks!

4
  • I do hope you are not on a slippery slope here... You shouldn't compose sql queries in C# with parameters (your ዜናገብርኤልስ)... you should use the SqlParameter object. That will implicitly solve all the unicode problems plus many other problems. Commented Aug 13, 2015 at 12:47
  • Dear, did you get my question first? am not asking you how to manipulate unicode characters in C#. am asking you how to query specific stored non english character from DB. Commented Aug 13, 2015 at 12:51
  • Yes... And I see you have tagged your question asp.net . So you don't seem to want to execute the query directly in the SQL Management Studio. So you want to execute the query from your program. So my warning is perfectly ok. Commented Aug 13, 2015 at 12:53
  • I understand your point. but before am going to C#, first i need to check the exact query from Sql Server management studio. that is why. n ways thanx alot. Commented Aug 13, 2015 at 12:58

1 Answer 1

3

You need to prefix your Unicode string literals with a N:

select DivisionName 
from t_Et_Divisions 
where DivisionName = N'ዜናገብርኤልስ'

This N prefix tells SQL Server to treat this string literal as a Unicode string and not convert it to a non-Unicode string (as it will if you omit the N prefix).

Update:

I still fail to understand what is not working according to you....

I tried setting up a table with an NVARCHAR column, and if I select, I get back that one, exact row match - as expected:

DECLARE @test TABLE (DivisionName NVARCHAR(100))

INSERT INTO @test (DivisionName)
VALUES (N'ዜናገብርኤልስ'), (N'ዜናገብርኤልስ,ኔትዎርክ,ከስተመር ስርቪስ'), (N'ኔትዎርክ,ከስተመር ስርቪስ')

SELECT * 
FROM @test
WHERE DivisionName = N'ዜናገብርኤልስ'

This returns exactly one row - what else are you seeing, or what else are you expecting??

Update #2:

Ah - I see - the columns contains multiple, comma-separated values - which is a horrible design mistake to begin with..... (violates first normal form of database design - don't do it!!)

And then you want to select all rows that contain that search term - but only display the search term itself, not the whole DivisionName column? Seems rather pointless..... try this:

select N'ዜናገብርኤልስ'
from t_Et_Divisions 
where DivisionName LIKE N'%ዜናገብርኤልስ%'

The LIKE searches for rows that contain that value, and since you already know what you want to display, just put that value into the SELECT list ....

Sign up to request clarification or add additional context in comments.

9 Comments

thank you for your quick response. i tried your query, but it will generate all the unicode characters that stored in DB, I need only to display this specific unicode character.
I'm sorry - I don't understand what you're saying - does this query work - or not?? I don't understand what you mean by generate all the unicode characters ? The query doesn't generate anything ......
i mean to say. i have 3 Nvarchar data type record in the table. when i execute the query, all 3 records will be generate. but i need only one record since i used where condition.
Do all those 3 rows have this value for DivisionName? Then of course all three of them are returned - that's how SQL SELECT works!
see, in DivisionName column you will have three value{ዜናገብርኤልስ,ኔትዎርክ,ከስተመር ስርቪስ} my question is how can you retrieve only ዜናገብርኤልስ ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.