ReadVitamin

Blogging on Teradata SQL and More

11 Comments

mygif
johnny Said in Friday, December 28th, 2007 @9:41 am  

how to create a macro which will execute the sql statements in it sequentially.
Eg:
sql1
success
sql2
else
exit

mygif
admin Said in Friday, December 28th, 2007 @9:13 pm  

Basically you are asking for multiple SQL statement processing, conditionally. You have to use BTEQ commands here. Here is an example which runs fine in a BTEQ session.

CREATE MACRO test AS
(SELECT date;
ECHO ‘.IF ERRORCODE = 0 THEN’;
SELECT time;);

Hope this helps.

mygif
punam Said in Thursday, March 13th, 2008 @5:44 am  

Hi,
Can we create and execute macros inside the procedure and how to use this?

Thanks & Regards
Punam

mygif
admin Said in Thursday, March 13th, 2008 @8:09 pm  

Hi Punam,

As per the Teradata rules, the EXECUTE statement is not supported by SPs. Only way we can use a Macro in SPs, is to use it as part of DECLARE CURSOR(macro form) within a Stored Procedure.

More to add, SP’s are designed to operate sequentially and not in parallel and when Macros return large set of rows as a recordset, SPs would have to process a lot more than the usual.

Hope this helps.

mygif
nehru Said in Monday, October 6th, 2008 @11:08 am  

so, is there a way to use results of a select that is stored inside a teradata macro ?

f.e. if we have a macor defined as:

replace macro abc as (
select * from abc.abc;
);

is there a way to do something like this:

select * from ()

?

mygif
nehru Said in Monday, October 6th, 2008 @11:15 am  

it should be

select * from (results of executing macro abc)

mygif
newbie Said in Wednesday, October 15th, 2008 @4:51 pm  

How to create marco which will output the data to a pipe delimited file?

mygif
Raman Said in Tuesday, December 9th, 2008 @9:51 am  

I have a macro that needs to accept a comma separated list of values-to be used in a sql - IN() clause.

create macro test(user varchar(1000)as
(
select * from user_list where user_id in (:user)
);

The problem is that whatever i enter into the parameter, the macro assumes it to be a single value instead of multiple values.
So if pass a single user, the macro returns values, but if i pass more than one eg: “100,101″ no records returned

Would appreciate any kind of help.

mygif
admin Said in Friday, December 12th, 2008 @10:42 pm  

Hi Raman,

Thank you for your question.

As per my understanding A “simple” Macro can not do this. There has to be a Stored Procedure. Try creating Stored Procedure and give it a shot.

Following code might help in creating a Stored Proc.

CREATE PROCEDURE MyProc(IN Values VARCHAR(150))
READS SQL DATA
DYNAMIC RESULT SETS 1
BEGIN
DECLARE InputStatement VARCHAR(500);
DECLARE ResultSet CURSOR WITH RETURN ONLY TO CLIENT FOR FirstStatement;

SET InputStatement = ‘SELECT * FROM TableName WHERE ColumnName IN (’ || Values || ‘);’;

PREPARE FirstStatement FROM InputStatement;
OPEN ResultSet;
END;

Hope that helps.

mygif
Nitin Said in Monday, September 7th, 2009 @6:54 am  

Hi,

I am new to teradata. I have some questions regarding Macros in Teradata.
1) what’s the difference between a Macro and Stored Procs?
2) Can we execute DDL in a Macro?

Thanks in advance,
Nitin

mygif
Rajesh Kumar Said in Sunday, January 24th, 2010 @6:45 pm  

Hi Admin, thanks for the q&a. I got query with Macro here. FYI,Im using Teradata12 and I ve tried Macro with numerous DML’s and as per Teradata rule, Macro can have only one DDL, that too as last stmt. Since DDL locks DD, we are using it in last line. but my question is I ve tried Macro with combination of DML n DDL, and im getting warning as “Data Dictionary must be solitary” and couldnt exec macro, Pls help me.\
Thanks,
Rajesh

Leave Your Comments Here

Popular Articles