When LTRIM/RTRIM Does Not Trim For You, You May Need to Remove Special Character You Cannot See (T-SQL)



DECLARE @STR varchar(max)='This sentense has tab and new line	
	
'

--TAB = char(9)
--LF = char(10)
--CR = char(13)

SELECT REPLACE(REPLACE(REPLACE(LTRIM(RTRIM(@STR)),CHAR(9), ''),CHAR(10),''),CHAR(13),'')


Advertisements

One Comment on “When LTRIM/RTRIM Does Not Trim For You, You May Need to Remove Special Character You Cannot See (T-SQL)”

  1. Jon says:

    This was a very short and clean way to remove the invisible characters (spaces included). Thanks, this was exaclty what I was looking for!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s