Tuesday, August 5, 2014

Remove Carriage Return, Line Feed, Tab in TSQL

Following code shows way to remove all spaces from selected column values. We generally use RTRIM and LTRIM build in string functions but sometimes it doesn’t remove some spaces due to string contains carriage return life feed and tab like control characters. We can’t see these characters with grid result view but we can see in text result view in MSS Management Studio.

REPLACE(REPLACE(REPLACE(RTRIM(LTRIM(ColumnName)), CHAR(10), ''),CHAR(13), ''),CHAR(9), '')
CHAR(9) - 'Tab'
CHAR(10) - 'Line Feed'
CHAR(13) - 'Carriage Return'

No comments:

Post a Comment