Saturday, February 25, 2012

create linefeed in field

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)
Whis SQL statement do i have to use?"Hans" <hans.de.korte@.prominent.nl> wrote in message
news:ae7dcba4.0402200557.1942ab24@.posting.google.c om...
> 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)
> Whis SQL statement do i have to use?

See CHAR() in Books Online.

Simon|||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

hans.de.korte@.prominent.nl (Hans) wrote in message news:<ae7dcba4.0402200557.1942ab24@.posting.google.com>...
> 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)
> Whis SQL statement do i have to use?

No comments:

Post a Comment