Groups | Blog | Home
all groups > sql server (alternate) > february 2004 >

sql server (alternate) : create linefeed in field


hans.de.korte NO[at]SPAM prominent.nl
2/20/2004 5:57:24 AM
Hello,

I would like to create more lines by concatenating values.
When I use: <select 'This' + ' ' + 'is' + ' ' + 'an' + ' ' +
'example'> the result is <This is an example> (on the same line).
I woul like to get:
<This
is
an
example> (each 'word' on a new line, but in 1 field)
user_google NO[at]SPAM hotmail.com
2/20/2004 12:00:28 PM
It looks like you are trying to format a string in SQL. It is always a
good practice to do this kind of formatting in the application. Given
that in order to add a line break as part of the string you need to
use the char function. char(13)+char(10) make a line break i.e. line
feed and carriage return. To answer your example you can try
declare @cf varchar(2)
set @cf=' '+char(13)+char(10)+' '
select 'This' + @cr + 'is' + @cf + 'an' + @cf + 'example'

If you don't want to use the variable then you substitute the variable
with the expression ' '+char(13)+char(10)+' '. As I mentioned before
it is not a best practice to do this kind of formatting at database
level.

Ramesh

[quoted text, click to view]
Simon Hayes
2/20/2004 6:23:36 PM

[quoted text, click to view]

See CHAR() in Books Online.

Simon

AddThis Social Bookmark Button