473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Mar 10 '06 #1
4 2087
Serge posted this one not too long ago. Do a search in this group for
XMLAGG.

B.

Mar 10 '06 #2
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?

Mar 13 '06 #3
James Conrad StJohn Foreman wrote:
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?

Wrap it into XML2CLOB(...)

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 13 '06 #4
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.

Mar 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: foodic | last post by:
i am fresher to C++ programming, and I just want to learn Concatenating Calls, I have written a program, class SetMe { public: void setX(int x) {_x = x;} void setY(int y) {_y = y;} void...
4
by: Juan | last post by:
Does any one know if there are reported bugs when concatenating strings? When debugging each variable has the correct value but when I try to concatenate them some values are missing (I can´t see...
16
by: bika | last post by:
I have a table that has values as follows: PersonID Degree 55 MD 55 Phd 55 RN 60 MD 60 Phd I need a create a query that will give me output like this:
3
by: bhaalsen | last post by:
Hi there! I got a slight problem with a web application, its supposed to several entries for a certain ID, and display them as one string. Example: ID | Name ------------- 1 | Jack
8
by: kingskippus | last post by:
I don't know if this is possible, but I haven't been able to find any information. I have two tables, for example: Table 1 (two columns, id and foo) id foo --- ----- 1 foo_a 2 foo_b
7
by: Mary | last post by:
I have a student who has a hyphenated first name. If I concatenate the name like this: StudentName:( & ", " & ), it works as expected. If, however, I try to get the first name first by...
6
by: dannylam4 | last post by:
Hello, I've got a question about merging/concatenating rows. There's a similar topic here: Combining Multiple Rows of one Field into One Result but I didn't know if I should hijack it. Basically, I...
1
by: firebirds98 | last post by:
I am trying to Concatene certain rows in a table but not all for instance I have a Course Track that consits of the classes CourseName Progressionorder Class 1 ...
3
by: banderson | last post by:
Hello all, I have a table "tblContacts" that holds my Contact Info. Because there can be multiple Contact Types for a Contact, I have a second table "tlnkContactTypes" in which there is a record for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.