如何附加到 t-sql SQL Server 2005 中的文本字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/466323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to append to a text field in t-sql SQL Server 2005
提问by Paul D. Eden
What is the best way to append to a text field using t-sql in Sql Server 2005?
在 Sql Server 2005 中使用 t-sql 附加到文本字段的最佳方法是什么?
With a varchar I would do this.
使用 varchar 我会这样做。
update tablename set fieldname = fieldname + 'appended string'
But this doesn't work with a text field.
但这不适用于文本字段。
回答by Bravax
Try this:
尝试这个:
update
tablename
set
fieldname = convert(nvarchar(max),fieldname) + 'appended string'
回答by Joe
Copied from link:
从链接复制:
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(ntextThing)
FROM item
WHERE id =1
UPDATETEXT table.ntextthing @ptrval NULL 0 '!'
GO
回答by SQLMenace
in 2005 you should use varchar(max) or nvarchar(max) these columns will work with normal varchar functions. Text and ntext have been deprecated
在 2005 年,您应该使用 varchar(max) 或 nvarchar(max) 这些列将与普通 varchar 函数一起使用。text 和 ntext 已被弃用
回答by Todd
The max length for varchar(max) is 2,147,483,647 characters. This is the same as the Text data type.
varchar(max) 的最大长度为 2,147,483,647 个字符。这与文本数据类型相同。
Whatever text could hold, this can hold, so you don't need to worry about running out of room by switching to VARCHAR(MAX).
无论文本可以容纳什么,这都可以容纳,因此您无需担心切换到 VARCHAR(MAX) 会导致空间不足。