How to pass the table name as a parameter/variable in teradata stored procedure to a select statement inside a loop? How to pass this table name <td_table_name> dynamically. I have a list of tables in another table and want to pass them in a loop.
REPLACE PROCEDURE TD_STORED_PRC()
BEGIN
DECLARE v_match_count INT;
FOR i AS cur CURSOR FOR
SELECT col_name
FROM **<td_table_name> ** ---- "this table name to read from input_table_list table and assign that table name value here"
DO
BEGIN
SET v_match_count = 0;
FOR j AS inner_cur CURSOR FOR
SELECT col_name
FROM td_table_name2
WHERE col_name = i.col_name
DO
SET v_match_count = v_match_count + 1;
BEGIN
INSERT INTO table3 (STATUS, INSERT_DATE_TIME)
VALUES ( 'Found', CURRENT_TIMESTAMP);
END;
END FOR;
END;
END FOR;
END;
I tried to write a subquery to get the table names from input_table_list but I think we can't pass table name using subquery. Is there a way to pass the table names from input_table_list in loop to the above procedure?