Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 newline in string

Author  Topic 

ratheeshsql
Starting Member

17 Posts

Posted - 2006-09-21 : 02:56:08
hi all..

i have a text field which has to be shown in the result of a query execution as several lines..

eg: the result should be like this

8STK :: L/2
: M/2
: S/1

Original string is stored as "8STK :: L/2 : M/2 : S/1"

expect a positive reply soon..
thanx..


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-21 : 03:39:05
select originalstring, replace(originalstring, ' : ', CHAR(10) + ': ')
from yourtable

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-09-21 : 04:00:43
quote:
Originally posted by Peso

select originalstring, replace(originalstring, ' : ', CHAR(10) + ': ')
from yourtable

Peter Larsson
Helsingborg, Sweden


Shouldn't it be the CR char(13) ?


KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-21 : 04:26:23
quote:
Originally posted by khtan

quote:
Originally posted by Peso

select originalstring, replace(originalstring, ' : ', CHAR(10) + ': ')
from yourtable

Peter Larsson
Helsingborg, Sweden


Shouldn't it be the CR char(13) ?


KH





Both works!

print 'accc' + char(13) + 'baaa' -- Line feed char
print 'accc' + char(10) + 'baaa' -- Carriage return char


...although there is technical difference between the two.



Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-09-21 : 04:33:13
quote:
Originally posted by harsh_athalye

quote:
Originally posted by khtan

quote:
Originally posted by Peso

select originalstring, replace(originalstring, ' : ', CHAR(10) + ': ')
from yourtable

Peter Larsson
Helsingborg, Sweden


Shouldn't it be the CR char(13) ?


KH





Both works!

print 'accc' + char(13) + 'baaa' -- Line feed char
print 'accc' + char(10) + 'baaa' -- Carriage return char


...although there is technical difference between the two.



Harsh Athalye
India.
"Nothing is Impossible"



You got it the other way round. 13 is CR, 10 is LF


KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-21 : 04:41:13
quote:
You got it the other way round. 13 is CR, 10 is LF


Yeah....my mistake

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

ratheeshsql
Starting Member

17 Posts

Posted - 2006-09-21 : 05:38:19
thanx...

i fixed that problem with char(13)..

Go to Top of Page
   

- Advertisement -