字符串或二进制数据将被截断:NVARCHAR(MAX)、SQL Server 2008
我有一个名为 description
的列,其类型为 NVARCHAR(MAX)
- 您可以拥有的最大的列。我需要返回这个字段并用引号引起来,所以我试图
SELECT QUOTENAME(description, '"')
这不起作用 - 我收到“字符串或二进制数据将被截断错误”。
我的谷歌搜索告诉我,这个问题可以通过使用 SET ANSI_WARNINGS OFF 来解决,但如果我这样做,我仍然会得到相同的错误。
通常,我只是将值提取到临时表中,并使用比我提取的字段大两个字符的字段,从而确保 QUOTENAME
函数不会导致任何问题。但是,如何使一列比 MAX 大两个字符呢?
I've got a column called description
of type NVARCHAR(MAX)
- biggest you can have. I need to return this field with quotes around it, so I'm trying to
SELECT QUOTENAME(description, '"')
This doesn't work - I get a "string or binary data would be truncated error."
My googling tells me that this problem can be solved by using SET ANSI_WARNINGS OFF, but if I do that, I still get the same error anyway.
Normally I would just pull the values into a temp table and use a field that is two characters bigger than the field I'm pulling in, thus ensuring that the QUOTENAME
function won't cause any problems. How do I make a column two characters bigger than MAX, though?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QUOTENAME
是一个用于处理包含 SQL Server 标识符名称的字符串的函数,因此仅适用于长度小于或等于sysname
的字符串 (128 个字符)。为什么
SELECT '"' + description +'"'
不适合您?QUOTENAME
is a function intended for working with strings containing SQL Server identifier names and thus only works for strings less than or equal to the length ofsysname
(128 characters).Why doesn't
SELECT '"' + description +'"'
work for you?