T-SQL appending data to NTEXT column

1.5k Views Asked by At

Can anyone help me figure out why I am getting the error below from the SQL script? Any and all help is greatly appreciated.

DECLARE @Comment AS VARCHAR(2000) 
DECLARE @Len AS INT
SET @Comment = 'This is a test and only a test!'
SET @Len = LEN(@Comment)
DECLARE @ptr varbinary(16)
SELECT @ptr = TEXTPTR(Comments)
FROM [dbo].[StudentInfringement] AS SI
WHERE [SI].[InfringementId] = 2
UPDATETEXT [dbo].[StudentInfringement].[Comments] @ptr @Len NULL @Comment

Error message is:

Msg 7135, Level 16, State 3, Line 9 Deletion length -19 is not in the range of available text, ntext, or image data. The statement has been terminated.

1

There are 1 best solutions below

0
On

What version of SQL Server?? I would strongly recommend you change your column to NVARCHAR(MAX) - NTEXT as a data type is deprecated as of SQL Server 2005, and it's just a royal pain to work with.

NVARCHAR(MAX) on the other hand easily supports all the usual string manipulation functions, and would be just all the much easier to use !