Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 10th, 2006, 05:55 PM
James Conrad StJohn Foreman
Guest
 
Posts: n/a
Default Concatenating rows ?

I've got a table full of search terms, one search term per row.

ID CATEGORYID SEARCH_TERM
1 1 cat
2 1 mat
3 2 sat
....

I need to get the search terms concatenated - is there an easy way to
achieve this?

If I knew how many search terms there were, I could join the table to
itself:

SELECT a.search_term || b.search_term
FROM search_terms a, search_terms b
WHERE a.categoryid = b.categoryid
AND a.id < b.id

(and expand this for n tables).

But I don't know how many search terms there are. Is there a simple
way to do this? Or is it some kind of repeating function that I need
to program?

Thanks

JCSJF

  #2  
Old March 10th, 2006, 06:15 PM
Brian Tkatch
Guest
 
Posts: n/a
Default Re: Concatenating rows ?

Serge posted this one not too long ago. Do a search in this group for
XMLAGG.

B.

  #3  
Old March 13th, 2006, 07:05 PM
James Conrad StJohn Foreman
Guest
 
Posts: n/a
Default Re: Concatenating rows ?

Thanks Brian, Serge.

select xmlagg(xmlelement(NAME a, email_address)) FROM
advertising.recipients;

Gives me
Function not supported (Reason code = "58"). SQLSTATE=42997

:-(

Running DB2 Express 8.2.1 on SLES 8. Do I need to be installing XML
extenders or something?

  #4  
Old March 13th, 2006, 09:35 PM
Serge Rielau
Guest
 
Posts: n/a
Default Re: Concatenating rows ?

James Conrad StJohn Foreman wrote:[color=blue]
> Thanks Brian, Serge.
>
> select xmlagg(xmlelement(NAME a, email_address)) FROM
> advertising.recipients;
>
> Gives me
> Function not supported (Reason code = "58"). SQLSTATE=42997
>
> :-(
>
> Running DB2 Express 8.2.1 on SLES 8. Do I need to be installing XML
> extenders or something?
>[/color]
Wrap it into XML2CLOB(...)

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
  #5  
Old March 15th, 2006, 03:25 PM
Brian Tkatch
Guest
 
Posts: n/a
Default Re: Concatenating rows ?

XML is an internal data type that is the required input for some
FUNCTIONs, and others output. However, it is not supported while
interfacing with the user.

The main FUNCTION is XMLAGG(), however, it requires the XML data typeas
its input, and outputs it as its datatype too. To make text into XML,
XMLElement() both changes the text to be XML and changes the data type
to XML. So much for the input. For the output, (as Serge pointed out)
XML2CLOB() turns it into a viewable data type.

Then you need to strip the XML tags (try select
substr(xml2clob(xmlelement(NAME a, email_address)), 1, 50) FROM
advertising.recipients; to see it). Which is <A> and </A> ("A" is the
NAME you specified.) So, REPLACE does that.

Finally, if you don't actually want a clob, SUBSTR() takes care of
that.

B.

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles