I have a situation where i am executing a series of create and insert statements using a BTEQ script.
but the issue is that a set of those statements have to run in a loop against a condition and continue with the rest of statements if the condition is satisfied.
Can anyone please suggest an example or how to achieve this .
Below is my scenario:
/*Identify if all negatives on first day were reconciled - Repeat steps until all negatives (<0) are deleted*/
------SET OF SQL CREATE TABLE AND INSERTS STMTS RUN HERE THEN;;;
DROP TABLE DEV_STG.chk;
CREATE MULTISET TABLE DEV_STG.chk AS
(SELECT record_id, charge_id,
MIN(CASE WHEN units <0 THEN service_day ELSE ' ' END) AS min_neg,
MIN(service_day) AS min_day
GROUP BY record_id, charge_id)WITH DATA;
SELECT COUNT(*) FROM DEV_STG.chk;
SELECT COUNT(*) FROM DEV_STG.chk WHERE min_neg = min_day AND min_neg <> ' ';
DROP TABLE DEV_STG.chk2;
CREATE MULTISET TABLE DEV_STG.chk2
(SELECT * FROM DEV_STG.chk WHERE min_neg = min_day AND min_neg <> ' ')WITH DATA ;
SELECT COUNT(*) FROM DEV_STG.chk2;
/*** IF ABOVE COUNT IS <0 THEN REPEAT THE LOOP* ***** ELSE RUN BELOW SET OF SQL STMTS.....***/
Please advice how to inset a loop in here .