471,607 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,607 software developers and data experts.

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 2038
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 XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.