Thursday, March 22, 2012

Remove New Line charactors from data in SQL

Some times we need to avoid newline characters and other characters such as tab from the data we retrieve from the SQL server. There is a easy way to do this, we just need to replace those characters with a space or what ever we need as follows.

declare @newLine char(2)
set @newLine = char(13) + char(10)

which is in SQL :
char(9) -  Tab
char(10) - Line feed
char(13)  - Carriage return

then we can directly replace these characters when ever we need.

e.g :-
select
replace(theDataBaseField,@newLine,' ' ) 
from.....

as above we can get data without any newline characters.

No comments:

Post a Comment