place all rows into one row

  • After some sql code earlier in this script, i end up with a temp table as below:

    oap

    ------

    apple1</br>

    apple2</br>

    What I'm trying to do is place all of the rows into a single row so I tried the following:

    select stuff((select oap from @OAP for xml path('')),1,1,'') as myApples

    this returns:

    oap>apple1</br ></oap><oap>apple2</br ></oap>

    What I'm tring to get is:

    apple1</br>apple2</br>

    How do I get all rows from the temp table into a single row? I sort of like the stuff with xml path minus the broken the first tag and the converted tags.

  • Try this...

    select stuff((select ' ' + oap from @OAP for xml path('')),1,1,'') as myApples

  • that produced:

    apple1</br > apple2</br >

    so how do i get to:

    apple1</br>apple2</br>

  • think this will work:

    select replace(stuff((select ' ' + oap from @OAP for xml path('')),1,1,''),'</br >', '</br>')

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

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