0

I have a database (SQL Server 2012) which has a lot of Unicode data. records inserted from a web application but character are saved in web character encoding 'western' but they are Unicode when this data shown in browsers, browsers automatically change their character encoding to 'Unicode' and show the characters correct but I want to use this data in my application and I want to change them in real Unicode characters

For examples character are saved in tables like this (with 'western' encoding):

Ù¾ÛŒØ´Ø±ÙØª 50 درصدی مخزن ذخیره آب بوشهر

and I want to convert them into unicode encoding like this :

پیشرفت 50 درصدی مخزن ذخیره آب بوشهر  
5
  • 4
    What datatype are your columns that store this data? In order to store and successfully retrieve Unicode characters, you must use NVARCHAR columns. Commented Dec 25, 2013 at 12:40
  • If they display on the web pages fine it must be stored correctly. The problem must be how your application handles them. Show us that. nvarchar is stored as UCS-2. This is not configurable. Commented Dec 25, 2013 at 12:46
  • all of my columns are nvarchar and the collation is Latin1 Commented Dec 25, 2013 at 12:50
  • If your columns are in fact NVARCHAR , then there is no encoding for those columns - they are Unicode - period. Were these column possibly of type varchar before and then converted to nvarchar after data had already been populated? Commented Dec 25, 2013 at 12:54
  • thats not application which handle it correctly ,thats the benefit of advanced browsers which detect charcter encooding correctly, so i want to have correct characters stored in my database ,because i want to show them in aother application which is not web based ! Commented Dec 25, 2013 at 12:56

1 Answer 1

1

Like Martin Smith and marc_s has explained you will need to use NVARCHAR datatype if you will be working with unicode character. Or you can use VARCHAR datatype with specific Arabic collation something like this

CREATE TABLE #TestTable
(
Column1 VARCHAR(100) COLLATE Latin1_General_100_CI_AI,  --<-- VARCHAR Column with Default Collation
Column2 VARCHAR(100) COLLATE Arabic_CI_AI_KS_WS,        --<-- VARCHAR Column with Arabic Collation
Column3 NVARCHAR(100),                                  --<-- NVARCHAR Column with Default Collation
Column4 NVARCHAR(100) COLLATE Arabic_CI_AI_KS_WS        --<-- NVARCHAR Column with Arabic Collation
)
INSERT INTO #TestTable 
VALUES(N'پیشرفت 50 درصدی مخزن ذخیره آب بوشهر'
       ,N'پیشرفت 50 درصدی مخزن ذخیره آب بوشهر'
       ,N'پیشرفت 50 درصدی مخزن ذخیره آب بوشهر'
       ,N'پیشرفت 50 درصدی مخزن ذخیره آب بوشهر')

SELECT * FROM #TestTable

Result

Column1                               Column2                               Column3                             Column4
?????? 50 ????? ???? ????? ?? ?????   پيشرفت 50 درصدي مخزن ذخيره آب بوشهر   پیشرفت 50 درصدی مخزن ذخیره آب بوشهر پیشرفت 50 درصدی مخزن ذخیره آب بوشهر
Sign up to request clarification or add additional context in comments.

3 Comments

I don't think this is the issue. Notice your example has question marks not random characters. They must be doing something else wrong.
@MartinSmith yes you are right, I think he has got some other Collation other then default or arabic , I reckon doing as I have suggested will fix the issue.
as i explained in comment ,already the datatype is NVARCHAR but characters are stored with western encoding , so i need to convert this character to Unicode!

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.