DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for SQL Server: Storing language specific data in SQL Server table field.
Sandeep Kumar
Sandeep Kumar

Posted on

SQL Server: Storing language specific data in SQL Server table field.

While working on multi-language support we need to insert different language data in the same field or different fields of a SQL Server table.

There are two basic rules one needs to keep in mind while storing multi-lingual or Unicode data:

  • First, the column must be of Unicode data type (i.e., nchar, nvarchar, ntext).
  • And second is that the value must be prefixed with N while insertion.

Below is the sample script with output to understand it better.

In the output, you can see that values in Var_Field are saved as ????, even though in script N is prefixed while inserting. This is because the field is of VARCHAR type.

Id Var_Field NVar_Field
1 ?? ?? ???? ?? เคฏเคน เคเค• เคถเคฌเฅเคฆ เคนเฅˆ
1 ?? ??? ???? ?? ????? ?? เจ‡เจน เจ‡เฉฑเจ• เจธเจผเจฌเจฆ เจฆเจพ เจนเฉเฉฐเจฆเจพ เจนเฉˆ

Note:

If you are using a stored procedure to insert the Unicode data, then make sure that N is used before the string while passing the parameter to the stored procedure. Also, make sure the parameter declared in the stored procedure is of Unicode type.


Originally published at http://diary-techies.blogspot.com on
July 19, 2016.

Top comments (1)

Collapse
 
aarone4 profile image
Aaron Reese

Just be aware that Unicode strings will preserve whitespace at the end of your strings. This can lead to some unexpected behaviour when using LIKE predicate matches. There are options to disable this behaviour.

๐ŸŒš Life is too short to browse without dark mode