Conditional statement in Teradata macro

Database
Enthusiast

Conditional statement in Teradata macro

I have a big list of stored procedures created in SQL server. I have to convert them to tereadata macros and need help in knowing logic for If and Else in a macro. Please help me with the macro structure. Thanks in advance.
6 REPLIES
Junior Supporter

Re: Conditional statement in Teradata macro

If there are procedural steps in the SQLServer store procedures, you should use Teradata stored procedures (Hey! They do exist!).

Macros cannot give you IF...THEN...ELSE functionality.

Macros are just SQL sentences bundled together and optionally parameterised.

HTH.

Cheers.

Carlos.
Enthusiast

Re: Conditional statement in Teradata macro

Thank you for responding.

Yeah, SP (stored procedures) exist in teradata, but currently Im not provided with any access to write any SPs, I have only macros access and im looking to embed any programming stuff in macros. Other than writing just queries, is there anything else that we can do through macros ??? (Im new to Teradata, so pls correct if my question is diverted).

WAQ
Enthusiast

Re: Conditional statement in Teradata macro

As CarlosAL said "Macros are just SQL sentences". You can not create or execute procedures using macros. You can create a macro that will reproduce your procedure body but still you need to execute it manually or by using dynamic SQL but for that you need rights to execute procedure.

Re: Conditional statement in Teradata macro

I think I'm having a similar issue as Sujjichalla. I am trying to get a simple select statement to run multiple times. I want to select a different department for which to select aggregate data on, and export to it's own Excel workbook. Is there a way for Teradata SQL to reference a separate list of Department names so as to satisfy the "Where" clause without me manually changing the query 20 times? 

Example that I have so far:

Select 

Department,

Category,

Sum (MO_ACT) AS MONTH_ACTUAL,

Sum (MO_BUD) AS MONTH_BUDGET,

Sum (MO_VAR) AS MONTH_VARIANCE,

Sum (YTD_ACT) AS YTD_ACTUAL,

Sum (YTD_BUD) AS YTD_BUDGET,

Sum (YTD_VAR) AS YTD_VARIANCE

FROM Expense_Input_2_2012

Group by Department, Category

WHERE Department = "Adult Medicine" 

Also, something is wrong with my syntax around adult medicine...

Any help? Been banging my head all day!!!

Re: Conditional statement in Teradata macro

Your select syntax should be order by step 

SELECT

FROM 

WHERE

GROUP BY

Enthusiast

Re: Conditional statement in Teradata macro

Hi,

in addition to the above sequence your string in WHERE Clause whould be enclosed in single qoutes, like this

WHERE Department = 'Adult Medicine'
Khurram