SQL Server TEXT columns are kind of special. Because of their size, and the fact that they're stored off-row, string manipulations must be considered wisely. Also, some of the functions that work for VARCHAR are not legal with TEXT. Here is a partial list (these samples assume a TEXT column called 'data'):
-- getting the number of characters SELECT LEN(data) -- becomes SELECT DATALENGTH(data) -- getting the first 5 characters SELECT LEFT(data,5) -- becomes SELECT SUBSTRING(data,1,5) -- getting the last 5 characters SELECT RIGHT(data,5) -- becomes SELECT SUBSTRING(data,DATALENGTH(data)-4,5) -- changing case SELECT LOWER(data) SELECT UPPER(data) -- becomes SELECT LOWER(SUBSTRING(data,1,DATALENGTH(data)) SELECT UPPER(SUBSTRING(data,1,DATALENGTH(data))
|
If you are attempting to REPLACE a part of the string, you can play with the STUFF() function, or see
Article #2445.