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.
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.
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…
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.
Hope this helps someone else.
2 thoughts on “The Power of N”
Hey, we all need the tidbits and reminders. I've never worked with Chinese in SQL, so I didn't know this…
Comments are closed.