Unicode characters issue in sql server


Yesterday when we got an issue such that Greek characters are going to customer with? Characters

ex:

String: “how are you  ”

Greek language is Γεια σου τι κάνεις

We have checked all the Procedures and found the issue that the one procedure is taking this greek letters are storing the data in the table variable like below

declare @tablevariable table

(

id int primary key  identity(1,1),

stringcolumn varchar(100)

)

 

insert @tablevariable values (N’Γεια σου τι κάνεις’)

 

select * from @tablevariable

 

Result:

 

Ge?a s?? t? ???e??

 

So we identified the issue and this is due to the stringcolumn data type and stringcolumn is using the data type varchar and it is the ASCII standard one and it is not supporting the UNICODE  language

Nvarchar  is the Unicode supported datatype

 

Below are the Unicode character data type

 

nchar

 

Fixed-length Unicode data with a maximum length of 4,000 characters.

 

nvarchar

 

Variable-length Unicode data with a maximum length of 4,000 characters.

 

ntext

 

Variable-length Unicode data with a maximum length of 2^30 – 1 (1,073,741,823) characters.

Ex:

declare @tablevariable table

(

id int primary key  identity(1,1),

stringcolumn nvarchar(max)

)

 

insert @tablevariable values (N’Γεια σου τι κάνεις’)

 

select * from @tablevariable

 

Result:

Γεια σου τι κάνεις

 

Please use the N before the string so that it will be identified as Unicode

Please let us know if you have any concerns on this.

 

Thanks for viewing

Leave a comment

Design a site like this with WordPress.com
Get started