Pages

Thursday, March 28, 2013

Prefix 'N' for Unicode values in SQL Server

Chances are that you have a nvarchar, nchar or ntext field in SQL Server which expects a Unicode value. However, when you INSERT/UPDATE the field, you literally end up having ????????????? in the field. So what went wrong.

It is important to understand that any n... field expects a Unicode value (for more information on Unicode, visit http://unicode.org/). This is done by prefixing the value with 'N' where N stands for National  Language Charter Set. The prefix dictates that the value is a Unicode value. SQL Server provides built in support of Unicode value. If we do not prefix the value with an 'N', the data is interpreted as ASCII value by SQL Server. The following example demonstrates this concept:


>
UPDATE
   Employee
SET
   ArabicName = N '...value...'
WHERE
   ID = ...id...

No comments:

Post a Comment