Query in SQL Server 2000

  • :

    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

  • Ankur

    Try this:

    SELECT REPLACE ('I Love India', ' ', CHAR(13) + CHAR(10))

    John

  • 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

  • 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

  • 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


    Regards,

    Steve

    Life without beer is no life at all

    All beer is good, some beers are just better than others

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply