{"id":254,"date":"2012-08-31T09:00:42","date_gmt":"2012-08-31T09:00:42","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/08\/31\/tsql-script-to-remove-tab-line-feed-and-carriage-return\/"},"modified":"2012-08-31T09:00:42","modified_gmt":"2012-08-31T09:00:42","slug":"tsql-script-to-remove-tab-line-feed-and-carriage-return","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/08\/31\/tsql-script-to-remove-tab-line-feed-and-carriage-return\/","title":{"rendered":"TSQL Script to remove TAB, LINE FEED and CARRIAGE RETURN"},"content":{"rendered":"

The below script removes the TAB(Horozontal Tab), Line feed(New line), Carriage Return Characters in a variable @String<\/p>\n

[sql]
\nSET NOCOUNT ON
\nDECLARE @String VARCHAR(100)
\nDECLARE @CorrectedString VARCHAR(100)<\/p>\n

SELECT @String = ‘ABC
\nD’<\/p>\n

PRINT @String<\/p>\n

SELECT @CorrectedString = REPLACE(@String, CHAR(9),”)
\nPRINT @CorrectedString<\/p>\n

SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(10),”)
\nPRINT @CorrectedString<\/p>\n

SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(13),”)
\nPRINT @CorrectedString
\n[\/sql]<\/p>\n

Extended script which also provides length of the string:
\n[sql]
\nSET NOCOUNT ON
\nDECLARE @String VARCHAR(100)
\nDECLARE @CorrectedString VARCHAR(100)<\/p>\n

SELECT @String = ‘ABC
\nD’<\/p>\n

PRINT @String
\nPRINT ‘LENGTH=’+CAST(LEN(@String) AS VARCHAR(5))<\/p>\n

SELECT @CorrectedString = REPLACE(@String, CHAR(9),”)
\nPRINT @CorrectedString
\nPRINT ‘LENGTH=’+CAST(LEN(@CorrectedString) AS VARCHAR(5))<\/p>\n

SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(10),”)
\nPRINT @CorrectedString
\nPRINT ‘LENGTH=’+CAST(LEN(@CorrectedString) AS VARCHAR(5))<\/p>\n

SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(13),”)
\nPRINT @CorrectedString
\nPRINT ‘LENGTH=’+CAST(LEN(@CorrectedString) AS VARCHAR(5))
\n[\/sql]<\/p>\n","protected":false},"excerpt":{"rendered":"

The below script removes the TAB(Horozontal Tab), Line feed(New line), Carriage Return Characters in a variable @String [sql] SET NOCOUNT ON DECLARE @String VARCHAR(100) DECLARE @CorrectedString VARCHAR(100) SELECT @String = ‘ABC D’ PRINT @String SELECT @CorrectedString = REPLACE(@String, CHAR(9),”) PRINT @CorrectedString SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(10),”) PRINT @CorrectedString SELECT @CorrectedString = REPLACE(@CorrectedString, CHAR(13),”) PRINT @CorrectedString…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1789],"tags":[],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/254"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}