469,133 Members | 1,037 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

Why cannot set Unicode string

Hi,

See this code:
DECLARE @SQL nvarchar(4000)
SELECT @SQL = 'SELECT * FROM CUSTOMER WHERE CustomerName = N''Trần
Tấn H*n'''
PRINT @SQL

The result always is this:
SELECT * FROM CUSTOMER WHERE CustomerName = N'Tr?n T?n H?n'

Sep 19 '06 #1
2 2015
Thang (th*****@gmail.com) writes:
See this code:
DECLARE @SQL nvarchar(4000)
SELECT @SQL = 'SELECT * FROM CUSTOMER WHERE CustomerName = N''Tr?n
T?n H?n'''
PRINT @SQL

The result always is this:
SELECT * FROM CUSTOMER WHERE CustomerName = N'Tr?n T?n H?n'
You forgot the N on the outer string, that is:

SELECT @SQL = N'SELECT * ...H?n'''

(Sorry my newsreader is not Unicode-capable, so it mangles your Vietnamese
characters.)

Without the N, the string is a varchar literal, and if your collation is
not a Vietnamese one, the Vietnamese characters are replace by fallback
characters.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Sep 19 '06 #2
Thank you.

Erland Sommarskog wrote:
Thang (th*****@gmail.com) writes:
See this code:
DECLARE @SQL nvarchar(4000)
SELECT @SQL = 'SELECT * FROM CUSTOMER WHERE CustomerName = N''Tr?n
T?n H?n'''
PRINT @SQL

The result always is this:
SELECT * FROM CUSTOMER WHERE CustomerName = N'Tr?n T?n H?n'

You forgot the N on the outer string, that is:

SELECT @SQL = N'SELECT * ...H?n'''

(Sorry my newsreader is not Unicode-capable, so it mangles your Vietnamese
characters.)

Without the N, the string is a varchar literal, and if your collation is
not a Vietnamese one, the Vietnamese characters are replace by fallback
characters.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Sep 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Weir | last post: by
8 posts views Thread by Bill Eldridge | last post: by
14 posts views Thread by Erik Bethke | last post: by
4 posts views Thread by webdev | last post: by
2 posts views Thread by Neil Schemenauer | last post: by
10 posts views Thread by Nikolay Petrov | last post: by
7 posts views Thread by 7stud | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.