Manipulate Data in TEXT Column

From Relyimah

Jump to: navigation, search

TEXT Columns are notoriously hard to deal with in both SQL Server and Oracle. This simple solution allows you to use SUBSTRING, REPLACE, and other commands with TEXT columns for SQL Server

Sql Server:

SELECT CAST(text_column AS VARCHAR(MAX)) FROM table_name

I believe this is related to SQL Server 2005 and greater.

A good example is removing Newlines and Breaks from a text column for display;

Sql Server:

REPLACE(REPLACE(REPLACE(REPLACE(CAST(text_column AS VARCHAR(MAX)), CHAR(10), ''), CHAR(13), ''), CHAR(9), ''), '<br />', ' ')
Personal tools