0

I'm having some trouble executing some macros in TERADATA. I have one big macro that includes 3 other macros. It looks like this:

create MACRO D_RISK_SANDBOX.saldo_pagos(fecha_desde date, fecha_hasta date, fecha_fin_desde date, fecha_fin_hasta date)
as
(
 exec D_RISK_SANDBOX.saldo ( :fecha_desde,:fecha_hasta);
 exec D_RISK_SANDBOX.pagos_cuotas( :fecha_desde,:fecha_hasta,:fecha_fin_desde,:fecha_fin_hasta);
 exec D_RISK_SANDBOX.pagos_refin( :fecha_desde,:fecha_hasta,:fecha_fin_desde,:fecha_fin_hasta);
)

exec D_RISK_SANDBOX.saldo_pagos('2016/08/01','2016/08/31','2016/09/01','2019/08/31')

Today I execute the big macro (D_RISK_SANDBOX.saldo_pagos) for each month I need. It would be easier to make a loop, but I don't know how. I've been reading about store procedures, but I don't know how to make a loop with dates. The dates could be in an array so I can have something like this: (The first column Is the date, the others columns are the result of each "little" macro)

enter image description here

1
  • 1
    I would suggest you ask yourself if you really need a loop. SQL is generally intended for set processing. Commented Jan 7, 2020 at 20:53

1 Answer 1

0

General date loop will look like this:

CREATE PROCEDURE proc_1 (IN date_1 date, IN date_2 DATE)
BEGIN
DECLARE DateCnt DATE;
  SET DateCnt = date_1;
WHILE DateCnt <= date_2 DO
BEGIN 
  set DateCnt = DateCnt + 1;
END ;
END WHILE;
END;

Calling:

call proc_1('2020-01-01','2020-01-07');
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.