Loop Statement in Teradata Stored Procedure

General
Fan

Loop Statement in Teradata Stored Procedure

Does anyone know how to write a loop statement within a Teradata stored procedure? Here's what I'm trying to accomplish:

SELECT......

FROM......

WHERE CUST_NAME = 'AMY'

SELECT......

FROM......

WHERE CUST_NAME = 'JAMES'

...ETC.

I need to be able to run the same query for each customer (e.g. 10 customers), one at a time. Each resulting output dataset will then be inserted into a master table.

Tags (1)
1 REPLY
Junior Contributor

Re: Loop Statement in Teradata Stored Procedure

Why different queries? 

Couldn't you simply use WHERE CUST_NAME = 'AMY' OR CUST_NAME = 'JAMES'?

Or if this was just an example and you're actually accessing different tables:

SELECT ...

UNION ALL

SELECT ...

UNION ALL

Dieter