Updates an existing text, ntext, or image field. Use UPDATETEXT to change only a portion of a text, ntext, or image column in place. Use WRITETEXT to update and replace an entire text, ntext, or image field.
UPDATETEXT {table_name.dest_column_name dest_text_ptr}
{
NULL
| insert_offset
}
{
NULL
| delete_length
}
[WITH LOG]
[
inserted_data
| [{table_name.src_column_name src_text_ptr}
]
Note If the WITH LOG option is not specified, the database must have the select into/bulkcopy database option turned on. For more information, see sp_dboption and Setting Database Options.
Newly inserted data can be a single inserted_data constant, table name, column name, or text pointer.
Update action | UPDATETEXT parameters |
---|---|
To replace existing data | Specify a nonnull insert_offset value, a nonzero delete_length value, and the new data to be inserted. |
To delete existing data | Specify a nonnull insert_offset value and a nonzero delete_length. Do not specify new data to be inserted. |
To insert new data | Specify the insert_offset value, a delete_length of 0, and the new data to be inserted. |
To initialize text columns to NULL, use UPDATETEXT when the compatibility level is equal to 65. If the compatibility level is equal to 70, use WRITETEXT to initialize text columns to NULL; otherwise, UPDATETEXT initializes text columns to an empty string. For information about setting the compatibility level, see sp_dbcmptlevel.
UPDATETEXT permissions default to those users with SELECT permissions on the specified table. Permissions are transferable when SELECT permissions are transferred.
This example puts the text pointer into the local variable @ptrval, and then uses UPDATETEXT to update a spelling error.
USE pubs
GO
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'
GO
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(pr_info)
FROM pub_info pr, publishers p
WHERE p.pub_id = pr.pub_id
AND p.pub_name = 'New Moon Books'
UPDATETEXT pub_info.pr_info @ptrval 88 1 'b'
GO
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'
GO
TEXTPTR | WRITETEXT |
READTEXT |