473,406 Members | 2,705 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,406 software developers and data experts.

How to compare the values from a table with a cursor in DB2

Expand|Select|Wrap|Line Numbers
  1. ID         SON              ACC
  2. 141    1    4511039999
  3. 141    1     131XXXXXXX
  4. 141    1     4411109999
  5. 141    1     5940029999
  6. 141    1     5940049999
  7. 141    1     4431009999
  8. 166    1    4511039999
  9. 166    1     131XXXXXXX
  10. 166    1     4411109999
  11. 166    1     5940029999
  12. 166    1     5940049999
  13. 166    1     4431009999
  14. 131    1    4511039999
  15. 131    1     131XXXXXXX
  16. 131    1     4411109999
  17. 131    1     5940029999
  18. 131    1     5940049999
  19. 131    1     4431009999
  20. 124    1    4511039999
  21. 124    1     131XXXXXXX
  22. 124    1     4411109999
  23. 124    1     5940029999
  24. 124    1     5940049999
my table data is like that one above , now i am trying to write a strored procedure to combine all the ACC's in the same ID into another table like

124 4511039999,131XXXXXXX,4411109999,5940029999

So in my stored procedure i fetched the ID and ACC's in a cursor and then how will i compare with the id's in the table through a loop


Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE GET_ACCOUNTS_IMPACTED ()
  2.     DYNAMIC RESULT SETS 1
  3. BEGIN
  4.  
  5.     DECLARE v_str varchar(100);
  6.     DECLARE v_acc_imp varchar(1000);
  7.     DECLARE v_control_id integer;
  8.     DECLARE v_control_id1 integer;
  9.  
  10.     BEGIN
  11.     DECLARE acc_imp_cur CURSOR WITH RETURN FOR
  12.         SELECT ACCOUNT_ID,CONTROL_ID FROM CONTROL_ACCOUNTS_IMPACTED ;
  13.  
  14.     DECLARE comp_cur CURSOR WITH RETURN FOR SELECT 
  15.          DISTINCT CONTROL_ID FROM CONTROL_ACCOUNTS_IMPACTED;
  16.  
  17.         OPEN acc_imp_cur;
  18.         OPEN comp_cur;    
  19.  
  20.         FETCH acc_imp_cur INTO v_str,v_control_id;
  21.         FETCH comp_cur INTO v_control_id1;                          
  22.  
  23.               SET v_str = CONCAT(v_str,',');
  24.  
  25.              WHILE(v_control_id = v_control_id1) DO
  26.  
  27.                 IF(LOCATE (',',v_str) > 0) THEN
  28.                     SET v_acc_imp = CONCAT(v_str,v_str);                    
  29.                     ELSE
  30.                         SET v_acc_imp = UPPER(v_str);
  31.                     END IF;                    
  32.                  SET v_acc_imp = v_acc_imp;         
  33.             END WHILE;
  34.  
  35.         INSERT INTO DUMMY_CAI1 (CONTROL_ID,ACCOUNTS_IMPACTED)
  36.         VALUES(v_control_id1,CASE WHEN v_acc_imp IS NULL THEN ' ' ELSE v_acc_imp END);                     
  37.     CLOSE acc_imp_cur;
  38.     END;
  39. END
this procedure is going into an infinite loop please give me a suggestion to loop through the values and get the code if any one knows
ASAP................

thanks in advance....
Nov 28 '07 #1
0 1203

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi All, I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a procedure and then I select from that dynamic table to...
1
by: Sascha | last post by:
Hi I need some help on achieving the following: I wrote a querie which collects Data out of three Tables, the Result looks like this: SET NOCOUNT ON DECLARE @ROW INT
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
0
by: Peter Wang | last post by:
I have a function and am using cursor. All the columns I select in the cursor clause are BYTEA datatype. I need to compare the after-fetch-value for two BYTEA columns which is temp2 and temp3...
3
by: bolly | last post by:
Hi, I've been putting Python data into a sqlite3 database as tuples but when I retrieve them they come back as unicode data e.g 'u(1,2,3,4)'.How can I change it back to a tuple so I can use it as...
4
by: SQLNewbie | last post by:
I have the following cursor that I am comparing 2 tables, the production table and a copy of the production table, I want results of all address's that are like the address1 field...the problem...
1
by: Sigmazen | last post by:
Hi I am looking in to utilising the new functionality of DPSIs on zOS UDB (DB2 v8), but I have a question regarding the following scenario. - The first table is an Account table whose columns...
1
by: san1014 | last post by:
Hi I have a table SQL> select * from nodes; NODE_ID NODE_NAME -------------------- ------------------------------ N1 Kothhapet N2 Nagole...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.