All Forums Database
sujjichalla 8 posts Joined 11/10
19 Nov 2010
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.

CarlosAL 512 posts Joined 04/08
19 Nov 2010

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.

sujjichalla 8 posts Joined 11/10
19 Nov 2010

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 158 posts Joined 02/10
22 Nov 2010

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.

babyjesus 2 posts Joined 11/10
21 Mar 2012

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!!!

nut_t02 1 post Joined 11/13
06 Nov 2013

Your select syntax should be order by step 
SELECT
FROM 
WHERE
GROUP BY
 

M.Saeed Khurram 544 posts Joined 09/12
06 Nov 2013

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

You must sign in to leave a comment.