Teradata stored procedure | how to use variable in dynamic sql

469 Views Asked by At

We are having below logic in stored procedure, we want to use variable "CARE_GAP" in select query highlighted in bold below, but its trying to check column CARE_GAP in table, which is not correct, select should take value from variable defined in stored procedure. Any quick help please

SET CARE_GAP = (SELECT CARE_GAP FROM V1 WHERE RANK1=I);

SET P_SQL_TEXT='INSERT INTO GAPS(INDIVIDUAL_ID, AGE, GENDER, PLAN_SPONSOR_ID,car_gap_NUMBER,ineligible, opEN1, cLOSE1) SELECT INDIVIDUAL_ID,AGE,GENDER,plan_sponsor_id,'||'"'||CARE_GAP||'"'||','||CARE_GAP||'_0 AS ineligible,'|| CARE_GAP||'_1 AS opEN1,'|| CARE_GAP||'_2 AS cLOSE1 FROM SB_PA_TDC.EDS_HIPPO_UNIFY_PROD_HISTORY_TEST;';

CALL dbc.SysExecSQL (P_SQL_TEXT);

0

There are 0 best solutions below