set pagesize 100;
set define ^
;

drop table t204_bill_fypd
/

create table t204_bill_fypd
     ( f_fypd1   char(6)   null
     , f_fypd2   char(6)   null
     , f_fypd3   char(6)   null
     , f_fypd4   char(6)   null
     , f_fypd5   char(6)   null
     , f_fypd6   char(6)   null
     , f_fypd7   char(6)   null
     , f_fypd8   char(6)   null
     , f_fypd9   char(6)   null
     , f_fypd10  char(6)   null
     , f_fypd11  char(6)   null
     , f_fypd12  char(6)   null
     , f_fypd13  char(6)   null
     )
/
commit
/

grant all on t204_bill_fypd to commbill_user
/

insert into t204_bill_fypd
select max(f_fypd), ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' 
  from t204_cb_ool_charges
/

update t204_bill_fypd  
   set f_fypd2 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd1)
/

update t204_bill_fypd  
   set f_fypd3 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd2)
/

update t204_bill_fypd  
   set f_fypd4 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd3)
/

update t204_bill_fypd  
   set f_fypd5 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd4)
/

update t204_bill_fypd  
   set f_fypd6 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd5)
/

update t204_bill_fypd  
   set f_fypd7 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd6)
/

update t204_bill_fypd  
   set f_fypd8 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd7)
/

update t204_bill_fypd  
   set f_fypd9 = (select max(f_fypd) 
                    from genfin_dbo.t740_fypd
                   where f_fypd < f_fypd8)
/

update t204_bill_fypd  
   set f_fypd10 = (select max(f_fypd) 
                     from genfin_dbo.t740_fypd
                    where f_fypd < f_fypd9)
/

update t204_bill_fypd  
   set f_fypd11 = (select max(f_fypd) 
                     from genfin_dbo.t740_fypd
                    where f_fypd < f_fypd10)
/

update t204_bill_fypd  
   set f_fypd12 = (select max(f_fypd) 
                     from genfin_dbo.t740_fypd
                    where f_fypd < f_fypd11)
/

update t204_bill_fypd  
   set f_fypd13 = (select max(f_fypd) 
                     from genfin_dbo.t740_fypd
                    where f_fypd < f_fypd12)
/

commit
/

select * from t204_bill_fypd
/

exit;
