Reputation: 20629
What is the best way to append to a text field using t-sql in Sql Server 2005?
With a varchar I would do this.
update tablename set fieldname = fieldname + 'appended string'
But this doesn't work with a text field.
Upvotes: 23
Views: 55181
Reputation: 439
The max length for varchar(max) is 2,147,483,647 characters. This is the same as the Text data type.
Whatever text could hold, this can hold, so you don't need to worry about running out of room by switching to VARCHAR(MAX).
Upvotes: 0
Reputation: 42666
Copied from link:
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(ntextThing)
FROM item
WHERE id =1
UPDATETEXT table.ntextthing @ptrval NULL 0 '!'
GO
Upvotes: 6
Reputation: 10493
Try this:
update
tablename
set
fieldname = convert(nvarchar(max),fieldname) + 'appended string'
Upvotes: 40
Reputation: 135171
in 2005 you should use varchar(max) or nvarchar(max) these columns will work with normal varchar functions. Text and ntext have been deprecated
Upvotes: 3