How To Read An NTEXT Column Using T-SQL READTEXT Function



TODO:

Have you ever wanted to read a NTEXT column from a Table in SQL Server

 

SOULTION:

DECLARE @Length int
DECLARE @ptrval varbinary(16)
		
SELECT @ptrval = TEXTPTR(MyTextColumn), @Length = Datalength(MyTextColumn) / 2
			FROM tbl_MyData where Id = 10023
			
READTEXT tbl_MyData.MyTextColumn @ptrval 0 @Length

 

 

NOTES:

You must divide the @Length by 2 in the select because NTEXT is a double-byte data type.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading