Wednesday, March 7, 2012

Retrieve records separated by spaces

Hello
I want to retrieve some records separated by spaces. Do you have any idea?
For example,
select col from T for xml path(''), root('x')
You get
<x>
<col>abc</col>
<col>def</col>
......
</x>
However I want to get,
<x>abc def ghi ... </x>
After post I got an idea, but looking for better one.
select @.x=(select col from T for xml path(''))
select @.x.query('
for $a in /col
return (concat(/$a/text(), " "))
')
for xml path
Any idea will be appreciated.
"Han" <hp4444@.kornet.net.korea> wrote in message
news:%233fljmVFHHA.4652@.TK2MSFTNGP04.phx.gbl...
> Hello
> I want to retrieve some records separated by spaces. Do you have any idea?
> For example,
> select col from T for xml path(''), root('x')
> You get
> <x>
> <col>abc</col>
> <col>def</col>
> .....
> </x>
> However I want to get,
> <x>abc def ghi ... </x>
>
|||This should be more elegant and performing (not tested - from memory)
select col as "data()" from T for xml path(''), root('x')
Best regards,
Eugene
"Han" <hp4444@.kornet.net.korea> wrote in message
news:%23aSIkxVFHHA.2268@.TK2MSFTNGP06.phx.gbl...
> After post I got an idea, but looking for better one.
> select @.x=(select col from T for xml path(''))
> select @.x.query('
> for $a in /col
> return (concat(/$a/text(), " "))
> ')
> for xml path
> Any idea will be appreciated.
> "Han" <hp4444@.kornet.net.korea> wrote in message
> news:%233fljmVFHHA.4652@.TK2MSFTNGP04.phx.gbl...
>
|||Thanks Eugene.
It worked.
"Eugene Kogan [MSFT]" <eugene.kogan@.online.microsoft.com> wrote in message
news:upkjKm$HHHA.4068@.TK2MSFTNGP03.phx.gbl...
> This should be more elegant and performing (not tested - from memory)
> select col as "data()" from T for xml path(''), root('x')
> Best regards,
> Eugene
> "Han" <hp4444@.kornet.net.korea> wrote in message
> news:%23aSIkxVFHHA.2268@.TK2MSFTNGP06.phx.gbl...
>

No comments:

Post a Comment