简体   繁体   English

SQL NVARCHAR(MAX) 返回 ASCII 和奇怪的字符而不是文本

[英]SQL NVARCHAR(MAX) returning ASCII and Weird Characters instead of Text

I have an SQL Table and I'm trying to return the values as a string.我有一个 SQL 表,我试图将值作为字符串返回。 The values should be city names like Sydney, Melbourne, Port Maquarie etc.值应该是城市名称,如悉尼、墨尔本、马夸里港等。

But When I run a select I either get black results or as detailed in the first picture some strange backwards L character.但是当我运行一个选择时,我要么得到黑色结果,要么在第一张图片中详细说明了一些奇怪的向后 L 字符。 The column is an NVARCHAR(MAX)该列是 NVARCHAR(MAX)

SELECT ctGlobalName FROM Crm.Cities

在此处输入图片说明

Then I tried using MSSQL's Edit top 200 rows feature and I could see the names of the cities, but also all these weird ascii characters.然后我尝试使用 MSSQL 的 Edit top 200 rows 功能,我可以看到城市的名称,但也可以看到所有这些奇怪的 ascii 字符。

在此处输入图片说明

Now I didn't create the database, I'm just running queries on it.现在我没有创建数据库,我只是在上面运行查询。 Some things I've read have suggested it is a problem with the Collation.我读过的一些内容表明这是排序规则的问题。 But the table is SQL_Latin1_General_CP1_CI_AS which matches the server collation.但该表是 SQL_Latin1_General_CP1_CI_AS 匹配服务器排序规则。

I'm sure there must be something I can add to my select query to return the values as an ordinary string.我确信必须有一些东西可以添加到我的选择查询中,以将值作为普通字符串返回。 Is there something I can do to my select query to return the expected format without the weird characters?我可以对我的选择查询做些什么来返回没有奇怪字符的预期格式?

An NVARCHAR datatype can store Unicode characters, which are used for languages that are not supported by the ASCII character set ie non-English (or related) languages such as Chinese or Indonesian. NVARCHAR 数据类型可以存储 Unicode 字符,这些字符用于 ASCII 字符集不支持的语言,即非英语(或相关)语言,如中文或印度尼西亚语。 If your SQL Server or Windows doesn't have that language installed then you might see strange-looking representations of the data.如果您的 SQL Server 或 Windows 没有安装该语言,那么您可能会看到看起来很奇怪的数据表示。

On the other hand, it could also be that the application that updates this table has just stored bad data in that column.另一方面,也可能是更新此表的应用程序刚刚在该列中存储了错误数据。

Either way you might need to do some string manipulation to strip out the characters you don't want.无论哪种方式,您都可能需要进行一些字符串操作以去除您不想要的字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM