February 23, 2007 at 5:59 am
:
Hi,
I have a string in field (in any table).
Suppose string is -- 'I Love India'(string can be of any length)
I want to write a query in sql server 2000 that gives the o/p in the following format--
I
Love
India
I,Love and India should come on 1st,2nd and 3rd line.Pls help me and send it on my hotmail id and Thanks in advance.
Ankur
February 23, 2007 at 6:11 am
Ankur
Try this:
SELECT REPLACE ('I Love India', ' ', CHAR(13) + CHAR(10))
John
February 26, 2007 at 8:21 am
Hi John,
Thanks for ur reply,but the query u send gives the o/p in 'I Love India' format and I want o/p in the order
I (in first row)
Love (2nd row)
India (3rd row)
can u help ?
Ankur
February 26, 2007 at 8:44 am
Ankur
I'm guessing you're looking at the result in grid format? That will always be displayed on one row. Try using Text format and see if that makes a difference.
If you want the output to be in different rows of a result set (and you did use the word "lines" instead of "rows" in your original post) then search this site for "parse" or "parsing". You can use the space as a delimiter and put each word in a separate row of a temp table.
John
February 26, 2007 at 7:05 pm
this works the way John described it
create table #temp_india
(
word varchar(20) )
go
insert
#temp_india (word)
SELECT
REPLACE ('I Love India', ' ', CHAR(13) + CHAR(10))
select
* from #temp_india
drop
table #temp_india
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply