Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 16 Feb 2005 @ 21:21:35 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Changing oracle code to teradata
 
From:   Dieter Noeth

hklein wrote:

  I am trying to change this oracle code into teradata. I am assuming it is in pl/sql. I am thinking of changing it using stored procedures but not sure if that is the right way.  


Rewrite as SP is the easiest way, but maybe not the most efficient. It's quite simple code, you can probably rewrite it as a single SQL statement.

This is more or less a 1:1 translation to Teradata syntax (untested):

     create procedure foo()
     BEGIN

     DECLARE

     last_date DATE;
     mean float;
     RESULT float;
     rec float;


     /********* determining the latest weekday in the table********/

     select max(a.Bus_date) into :last_date from payments a;


     /********* counting records on the latest weekday *********/

     select count(*) into :rec from payments a where a.BUS_DATE = last_date;

     /********* counting sum of all records for the same weekday in last 8 months ***/

     select avg(cnt) into :mean from
       (
        select count(*))
        from payments a
        where a.BUS_DATE > (last_date - 240) and a.BUS_DATE < last_date
        and ((last_date - a.BUS_DATE) mod 7) = 0
        group by a.BUS_DATE
       );


     /***** calculating mean and variance *********/

     RESULT := cast(((rec - mean)*100/mean) as dec(18,2));

     /********** inserting in metrics table *******/
     INSERT INTO TDI_DAILY VALUES (current_date, 'PAYNUM', :RESULT, NULL,
     upper('TESTED ' || last_date || ' - ' || (last_date (format 'eeee'))));

     END;


     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023