troubleshooting Question

change the select dynamically

Avatar of pvsbandi
pvsbandiFlag for United States of America asked on
DB2
2 Comments1 Solution491 ViewsLast Modified:
Hi,

 I have two select statements in my procedure. I have to use them in a for loop dynamically.
 This is how i tried, but didn't work. can someone kindly help get it to work?
CREATE PROCEDURE CHESSIE.PROCEDURE1 (  )
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
DECLARE C1 VARCHAR(10) DEFAULT 'A';
 DECLARE  GLOBAL TEMPORARY TABLE ABC(C_ID INTEGER);

FOR CUR1 AS
CASE WHEN C1 = 'A' THEN
SELECT CLIENT_ID FROM TB_CLIENT
ELSE SELECT CLIENT_ID FROM TB_PROVIDER
END CASE
 DO

INSERT INTO SESSION.ABC
SELECT CUR1.CLIENT_ID;
END FOR;
END P1    
ASKER CERTIFIED SOLUTION
momi_sabag

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros