Retrieving ntext, text, or image Values

You can retrieve ntext, text or image values by:

Retrieving Parts of ntext, text, or image Values

These methods are not limited to retrieving the entire ntext, text, or image value starting with the first byte. The methods can be combined to provide flexible processing that retrieves different parts of the ntext, text, or image values. For example, this SELECT statement retrieves whatever part of a text value is between a start tag and an end tag:

USE Northwind

GO

CREATE TABLE TextParts (ColA INT PRIMARY KEY, ColB TEXT)

GO

INSERT INTO TextParts

   VALUES( 1,

           'Sample string START TAG What I want END TAG Trailing text.')

GO

SELECT SUBSTRING(   ColB,

                    /* Calculate start as start of tag + tag length. */

                    (PATINDEX('%START TAG%', ColB) + 10),

                   /* Calculate SUBSTRING length as end - start. */

                    (

                      PATINDEX('%END TAG%', ColB) -

                      ( PATINDEX('%START TAG%', ColB) + 10 )

                    )

                )

FROM TextParts

GO

  

Here is the result set:

------------------------

What I want

  

(1 row(s) affected)

  


Note When you are selecting image data, the returned value includes the characters 0x, which indicate that the data is hexadecimal. These two characters are counted as part of TEXTSIZE.


See Also
READTEXT SET TEXTSIZE
SELECT Text and Image Functions
BLOBs and OLE Objects Using Long Data Types
Managing text and image Columns  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.