I need help to compare 2 variables inside Teradata BTEQ script and take a decision based on the outcome. I tried something like below:
CREATE VOLATILE TABLE VT_JRNL_MAX_SNAPSHOT_DT,NO LOG,NO FALLBACK
(
MAX_DATE_JRNL DATE FORMAT 'YYYY-MM-DD'
);
INSERT INTO VT_JRNL_MAX_SNAPSHOT_DT
(
MAX_DATE_JRNL
)
SELECT MAX(JOURNAL_SNAPSHOT_DATE) FROM NDW_NRDP_TABLES.NRDP_EWFM_AGENT_SEGMENT_JRNL;
CREATE VOLATILE TABLE VT_SEM_MAX_SNAPSHOT_DT,NO LOG,NO FALLBACK
(
MAX_DATE_SEM DATE FORMAT 'YYYY-MM-DD'
);
INSERT INTO VT_SEM_MAX_SNAPSHOT_DT
(
MAX_DATE_SEM
)
SELECT MAX(JOURNAL_SNAPSHOT_DATE) FROM NDW_NRDP_TABLES.NRDP_EWFM_AGENT_SEGMENT;
.IF MAX_DATE_JRNL >= MAX_DATE_SEM THEN .GoTo DEL_STEP ;
.IF MAX_DATE_JRNL < MAX_DATE_SEM THEN .GoTo EXIT_STEP ;
.LABEL DEL_STEP ;
DEL FROM SEMANTIC;
.LABEL EXIT_STEP ;
INSERT ......;
Thanks, Debasis
An easy variable in BTEQ which can be helpful here is
ACTIVITYCOUNT
With this, you can formulate a query like:
There may be more neat ways to write this query to avoid cross join and even avoid the volatile tables entirely. But this should serve as a starting point.