'From Varchar to Nvarchar with 'N' prefix

I have a table with thousands of rows. One of the columns does not read the values correctly. Some letters cannot be recognised and thus changed to some symbols like in the attached screenshot. I found that if the values are given in Nvarchar format with 'N' prefix, then I get the correct result. Since I cannot change every single row in the table, I wanted to ask if there is a way to change Varchar to Nvarchar and also include the 'N' prefix, because without prefix Nvarchar does not help.

Screenshot of an example



Solution 1:[1]

CREATE TABLE fg_test_geo(
   budesland VARCHAR(30) 
  ,nbudesland NVARCHAR(30)
);
INSERT INTO fg_test_geo(budesland,nbudesland) VALUES ('bucure?ti',N'bucure?ti');

We could alter the existing varchar column to nvarchar, or as in this example, we coud add a computed column casting the existing data to nvarchar:

alter table fg_test_geo
add [cbudesland] as (cast(budesland as nvarchar(30)))
select *
from fg_test_geo
budesland | nbudesland | cbudesland
:-------- | :--------- | :---------
bucure?ti | bucure?ti  | bucure?ti 

So what you can see from this is that casting varchar to nvarchar won't "fix" the existing data, but if you were to change that data type AND you use the N prefix for inserts and updates, then you can store the extended characters that nvarchar allows.

db<>fiddle here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul Maxwell