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 > working with stored pprocedures

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-21-09, 10:37
db2id db2id is offline
Registered User
 
Join Date: Apr 2009
Posts: 5
working with stored pprocedures

Hi All,

I have a table which has values say
del_id pt_phase
1 red
1 black
2 red
2 black

I need like
del_id pt_phase
1 red,black
2 red,black

I have written a stored procedure to concatenate the pt_phase.
But this will work fine if i have the unique del_id.ie I have to traverse through the records of "select distinct(del_id) from table name" each time and insert values.
In the below code I dont know how to get ditinct(del_id) and work with it.
If i harcode value eg"1" insead of del_id it is working fine
Please help!!

CREATE PROCEDURE CONCAT1()
LANGUAGE SQL
BEGIN ATOMIC
DECLARE s_phase VARCHAR(1000);

SET s_phase = '';

FOR v as cur1 CURSOR FOR
(
SELECT
ADMINISTRATOR.TABLE_TRUNC_PRODQUALITY.PQ_TASK_PHAS E_NAME AS PQ_TASK_PHASE_NAME

FROM
ADMINISTRATOR.TABLE_TRUNC_PRODQUALITY
WHERE
ADMINISTRATOR.TABLE_TRUNC_PRODQUALITY.del_id = del_id
ORDER BY
ADMINISTRATOR.TABLE_TRUNC_PRODQUALITY.PQ_TASK_PHAS E_NAME
)
DO
IF s_phase = '' THEN
SET s_phase = v.PQ_TASK_PHASE_NAME;
ELSE
SET s_phase = s_phase || ', ' || v.PQ_TASK_PHASE_NAME;
END IF;
END FOR;
INSERT INTO test_prodquality VALUES (v.del_id,s_phase) ;
END
@

Last edited by db2id; 04-21-09 at 10:40.
Reply With Quote
  #2 (permalink)  
Old 04-21-09, 13:17
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
This type of question gets asked a lot. Try using recursion. If you need help, search the forum.

Andy
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