The Power of N

A peer the other day was having some trouble storing some some Chinese characters in a database.  Every time he would insert the data into his table, the results would look similar to the following.

image

The phrase he was adding was similar to the following:

烟肉独角兽彩虹乳酪

The T-SQL he was using was forwarded to me and it looked like the following:

USE tempdb
GO

CREATE TABLE #AnotherLanguage
(Chinese nvarchar(50))
GO

INSERT INTO #AnotherLanguage
VALUES('烟肉独角兽彩虹乳酪')
GO

SELECT * FROM #AnotherLanguage

The title may have given a hint as to the issue he was facing.  To pass the string into the table as nvarchar it needs to be prefaced with the letter N.  One character with so much power.

See below…

USE tempdb
GO

CREATE TABLE #AnotherLanguage
(Chinese nvarchar(50))
GO

INSERT INTO #AnotherLanguage
VALUES(N'烟肉独角兽彩虹乳酪')
GO

SELECT * FROM #AnotherLanguage

This time the results are the following…

image

Not exactly an exciting issue, but a helpful one to recall none the less.  There was one other thing that needed to be done, that was a quick update to the installed languages.  This, though, didn’t seem to be an issue on my Windows 7 machine.

image001

Hope this helps someone else.

2 thoughts on “The Power of N

Comments are closed.