How to pass a parameter into a sql query in Teradata
Solution:
Create a Macro in Teradata. A Macro is pretty much just a parameterized view,
CREATE MACRO myMacro (parameter1 VARCHAR(20), parameter2 DATE)
AS
(
SELECT t1.*
FROM table1 t1
LEFT JOIN
(
SELECT t2.col1, t3.col2, SUM(t3.col3)
FROM table2 t2
INNER JOIN table3 t3
WHERE t3.col2 NOT LIKE :parameter1
GROUP BY 1,2
QUALIFY ROW_NUMBER() OVER(PARTITION BY t2.col1 ORDER BY t3.col1) = 1
) x
ON t1.col1 = x.col1
WHERE t1.START_DATE >= :parameter2;
);
To call it:
Exec myMacro('Harold', DATE '2015-01-01');
dan-irving
posted on 09 Aug 18Enjoy great content like this and a lot more !
Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds
Post Comment