If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Query question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-15-08, 16:06
jclark01 jclark01 is offline
Registered User
 
Join Date: Jan 2008
Posts: 2
Query question

My business system vendor, in their great wisdom, has constructed a table in a difficult to use format. The table hold comments that are input into a text box on a web form, or through a Green Screen application. The input box allows for multiple lines so they store each line of the input in a seperate record with an ID number in the first column, a line number in the second column, and one line of the text field in the third column. The ID number then repeats and the line number increments for each line that was input.

I need to find a way, preferably using SQL to view this data in a more concise form with a single record containing the entire comment with each record containing the ID number in the first column and all of the lines of text concatenated together in the second column.

I have seached in vain for a method to do this but it is difficult to describe to a search engine what I am trying to do. Does anyone have any ideas?
Reply With Quote
  #2 (permalink)  
Old 01-15-08, 16:50
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You want to concatenate strings. Search a bit here or on your favorite search engine - you will find lots of material. Basically, you can use recursive queries or the XMLAGG function (DB2-specific) to perform the aggregation.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development

Last edited by stolze; 01-16-08 at 02:55.
Reply With Quote
  #3 (permalink)  
Old 01-15-08, 22:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
you want what mysql's GROUP_CONCAT function does trivially

you neglected to mention which DBMS you're using, which is often important when an ANSI SQL solution may be difficult
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 01-16-08, 11:18
jclark01 jclark01 is offline
Registered User
 
Join Date: Jan 2008
Posts: 2
Sorry, My DBMS is DB2 on OS/400 V5R4
Reply With Quote
  #5 (permalink)  
Old 01-16-08, 17:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
moving thread to DB2 forum
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 01-20-08, 12:59
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by jclark01
I need to find a way, preferably using SQL to view this data in a more concise form with a single record ...
Is an SQL stored procedure an option?
Then you just need to open a cursor (returning the rows in the right order), concat the rows into a local variable, and return that variable.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On