As said before create a macro and pass a variable. Remember you can not use dynamic SQLs in a Macro. Also you can create a volatile (temporary) table which lives until the session is active, so here is the code on how to create a volatile table. Suppose you want to hold today’s date in a temp variable/table here is the way to do it.
CREATE VOLATILE TABLE today_date AS
(SELECT DATE) WITH DATA ON COMMIT PRESERVE ROWS;
In case you do not want to see the results after you run the query, then use DELETE in place of PRESERVE which deletes the row as soon as the query finishes. This is helpful if you are doing any transactional query.
If you are wondering how to create macro, here is the way.
CREATE MACRO macro_name (<param1> datatype, <param2> datatype) AS
([INSERT…;][UPDATE…;][DELETE…;][SELECT…;] );
For example;
CREATE MACRO my_macro( InVal INTEGER)
( Update mytable set mycolumn = mycolumn *5/100
WHERE myothercolumn = :InVal;
SELECT mycolumn, myothercolumn
From myothertable
WHERE myothercolumn = :InVal);
How to execute/run this Marco, here is how;
EXECUTE (EXEC) <macro_name> [parameter value list]
For Example; EXEC my_macro ( 4545);EXEC my_macro ( InVal = 4545);
If you have more than one parameters and using name for value assignment, the sequence of the parameter in the EXEC does NOT matter.
What is equivalent to Oracle’s Dual table in Teradata?
Good question, actually there is no such table present in Teradata. But the same functionality can be derived by the following code. Before that just to remind that the Dual table in Oracle is used for intermediate calculations, like selecting a date and calculating something. In Teradata it is done without the use of any such table.
In Oracle if you are using
SELECT SYSDATE FROM DUAL
In Teradata the same can be achieved by the following shorter command;
SELECT DATE
Isn’t it COOL!
How to Change your Password in Teradata
This command is pretty similar to the command in Oracle.
MODIFY USER userid AS PASSWORD = yournewpassword
Our Random Articles
- Somdev Devvarman ousts Xavier Malisse 6-1, 3-6,7-6(5)
- How To Choose A Good Online Traffic School
- New Year Wishes 2010
- New Year Wishes
- How to use EXTRACT function with date and time columns
More Links




4 Comments
Material that you are providing is very easy to learn. But it is much better than this , if you ll give the full material of this at ONE LINK.
Thank you
Suresh.
That is right Suresh. This is the reason I have given all the links in one page, please visit this
http://readvitamin.com/teradata/
Hope this helps.
Hi. Can anyone tell me how to extract time from timestamp?
For Example
timestamp=’2008-03-28 14:11:04′
i want time ’14:11:04′ from timestamp through query.
Thanks in advance.
Hi Vaideesh,
If you need only time, you can probably try the following;
SELECT time;
To answer your question you should do something like this.
SELECT CAST(VaideeshTime as time(0)) from timestamp;
VaideeshTime
——–
14:11:04
Hope that helps.