/************************************************************************
  process through the profile table and create the SYSTEM reports 
 ************************************************************************/

declare c281rpt cursor for
 select f_loc_c          
      , f_div_c         
      , f_dpt_c        
      , f_invtyp_c    
      , f_syssrc_c   
      , f_stg_c     
      , f_fop_c    
      , f_afm_c   
      , f_srt_c
      , f_acct_c        
      , i_nsid_c          
      , i_spec_c         
      , f_expr_x       
      , f_ord_x  
      , f_grp_x      
      , f_div_x     
      , f_bu_x
      , convert(decimal(15,2),f_inv_a)        
      , f_glval_i    
      , f_prof_x          
      , a_uid_c           
    from d280db1.dbo.t280prof
   where a_uid_c = 'SYSTEM'
/*   and f_calc_i = 'Y' */
go

declare 
   @bpd char(6)   
 , @epd char(6)   
 , @loc char(3)   
 , @div char(3)   
 , @dpt char(4)   
 , @typ char(10)  
 , @src char(6)   
 , @stg char(3)   
 , @fop char(6)   
 , @afm char(3)  
 , @srt char(15)
 , @act char(6)   
 , @dev char(15)  
 , @spc char(8)   
 , @exp char(20)  
 , @ord char(25)  
 , @grp char(30)  
 , @dvn char(30)  
 , @bus char(30)  
 , @amt decimal(15,2) 
 , @glv char(1)   
 , @prof char(50) 
 , @user char(8)  
 
select @epd = (select max(f_fypd) from d280db1.dbo.t280fypd)
select @bpd = (select max(f_fypd) from d280db1.dbo.t280fypd where f_fypd < @epd)

print ' beg pd:' 
print @bpd
print ' end pd:'
print @epd

open c281rpt

Begin_loop:
fetch c281rpt
 into 
   @loc 
 , @div 
 , @dpt 
 , @typ 
 , @src 
 , @stg 
 , @fop 
 , @afm 
 , @srt 
 , @act 
 , @dev 
 , @spc 
 , @exp 
 , @ord 
 , @grp 
 , @dvn 
 , @bus 
 , @amt 
 , @glv 
 , @prof 
 , @user 
           
if @@sqlstatus <> 0
   goto ENDIT    

print " ----------------------- "
print " "
print @prof
select getdate()

exec p280_p007
   @bpd 
 , @epd 
 , @loc 
 , @div 
 , @dpt 
 , @typ 
 , @src 
 , @stg 
 , @fop 
 , @afm 
 , @srt 
 , @act 
 , @dev 
 , @spc 
 , @exp 
 , @ord 
 , @grp 
 , @dvn 
 , @bus 
 , @amt 
 , @glv 
 , @prof 
 , @user 
 
goto Begin_loop

ENDIT: 

go
