Datatype Change

  • Changed one of the existing column datatype from varchar(250) to nvarchar(250) but the column still showing arabic characters as ??

    How can i resolve this?

  • We need a lot more detail.   It appears likely that the data you have is not standard English characters, but just changing a datatype from varchar to nvarchar only provides the means to store unicode characters.   As the column was varchar at the time it was populated, if there were unicode characters being used, then such characters were likely converted, possibly implicitly, at the time the data was inserted or updated into the table, and one of the possible consequences is that information got lost in that conversion.   You'll need to provide more specific details and as much specific history of events as you can in order for someone to be able to help much.   One other possibility is that you just have foreign language characters, and you may just need to set the proper collation for that column, but that seems a lot less likely.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • VastSQL - Monday, March 5, 2018 5:42 AM

    Changed one of the existing column datatype from varchar(250) to nvarchar(250) but the column still showing arabic characters as ??

    How can i resolve this?

    As Steve mentioned, once the data is saved or converted into varchar, there's no way to get the unicode data back.
    If after the data type change, you still can't store the arabic characters correctly, you need to check your string handling. Here's an example of what I mean.

    DECLARE @test-2 TABLE( MyString nvarchar(250));

    INSERT INTO @test-2 VALUES('طالÙٱئذش'); --Random string without any knowledge on what it means
    INSERT INTO @test-2 VALUES(N'طالÙٱئذش');

    SELECT *
    FROM @test-2;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares - Monday, March 5, 2018 6:33 AM

    VastSQL - Monday, March 5, 2018 5:42 AM

    Changed one of the existing column datatype from varchar(250) to nvarchar(250) but the column still showing arabic characters as ??

    How can i resolve this?

    As Steve mentioned, once the data is saved or converted into varchar, there's no way to get the unicode data back.
    If after the data type change, you still can't store the arabic characters correctly, you need to check your string handling. Here's an example of what I mean.

    DECLARE @test-2 TABLE( MyString nvarchar(250));

    INSERT INTO @test-2 VALUES('طالÙٱئذش'); --Random string without any knowledge on what it means
    INSERT INTO @test-2 VALUES(N'طالÙٱئذش');

    SELECT *
    FROM @test-2;

    Thanks Luis,

    Data get inserted using Linq query and we tried creating a new nvarchar column inserted into both column the same value at once and the new column is populating data properly but the column we changed from varchar to nvarchar is still showing data as ??

  • VastSQL - Tuesday, March 6, 2018 3:08 AM

    Thanks Luis,

    Data get inserted using Linq query and we tried creating a new nvarchar column inserted into both column the same value at once and the new column is populating data properly but the column we changed from varchar to nvarchar is still showing data as ??

    If it's data that was already in the table before the data type change, then it's lost. You would need to correct it as there's nothing stored that would allow you to identify which were the characters that you intended to store in the first place.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • VastSQL - Monday, March 5, 2018 5:42 AM

    Changed one of the existing column datatype from varchar(250) to nvarchar(250) but the column still showing arabic characters as ??

    How can i resolve this?

    Once the Unicode data was converted to non Unicode data and stored in the varchar(250) column the data is lost.  Converting the column to nvarchar(250) will not recover the data.  You will have to go back to the original source to recover the data.

    Edit:  Should have read further, sorry for repeating what has already been said.

  • Lynn Pettis - Tuesday, March 6, 2018 8:44 AM

    VastSQL - Monday, March 5, 2018 5:42 AM

    Changed one of the existing column datatype from varchar(250) to nvarchar(250) but the column still showing arabic characters as ??

    How can i resolve this?

    Once the Unicode data was converted to non Unicode data and stored in the varchar(250) column the data is lost.  Converting the column to nvarchar(250) will not recover the data.  You will have to go back to the original source to recover the data.

    Edit:  Should have read further, sorry for repeating what has already been said.

    Thanks Lynn
    I am talking about new data being inserted after changing the data type

  • Look at your LINQ. Is it still mapping the column as ascii text?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster - Wednesday, March 7, 2018 1:03 AM

    Look at your LINQ. Is it still mapping the column as ascii text?

    Thanks Gail.

    Finally find the issue. In Db context the unicode was set to false. Developer changed it to True and now its working as expected.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply