
drop proc p280_p006f
go

create procedure p280_p006f
/*
  -----------------------------------------------------------------------
      P280_P006F - Inventory Analysis Report - PRINT reports from t280rpt.
  -----------------------------------------------------------------------
*/

/*
    ------  INPUT VARIABLES   ------
*/
   @exp char(20)  = "01. None'"
 , @ord char(25)  = "01. Category"
 , @amt decimal(15,2) = 0
 , @prof char(50) = "1."
 , @user char(8)  = "SYSTEM"
as

/***********************************************************************
   Summarize the period totals by the Report Group and insert them into
   the temporary table #t280_sum with default values for the Impact %'s.
 ***********************************************************************/

/***********************************************************************
   Control Section for Printing and Ordering the Reports
 ***********************************************************************/

if @ord = '01. Category'
   goto OrderByCategory

if @ord = '02. IMPACT QTY ASC'
   goto OrderByQtyA

if @ord = '03. IMPACT QTY DESC'
   goto OrderByQtyD

if @ord = '04. IMPACT AMT ASC'
   goto OrderByAmtA

if @ord = '05. IMPACT AMT DESC'
   goto OrderByAmtD

if @ord = '06. IMPACT QTY % ASC'
   goto OrderByQtyPctA

if @ord = '07. IMPACT QTY % DESC'
   goto OrderByQtyPctD

if @ord = '08. IMPACT AMT % ASC'
   goto OrderByAmtPctA

if @ord = '09. IMPACT AMT % DESC'
   goto OrderByAmtPctD

if @ord = '10. LEFT QTY ASC'
   goto OrderByLeftQtyA

if @ord = '11. LEFT QTY DESC'
   goto OrderByLeftQtyD

if @ord = '12. LEFT AMT ASC'
   goto OrderByLeftAmtA

if @ord = '13. LEFT AMT DESC'
   goto OrderByLeftAmtD

if @ord = '14. RIGHT QTY ASC'
   goto OrderByRightQtyA

if @ord = '15. RIGHT QTY DESC'
   goto OrderByRightQtyD

if @ord = '16. RIGHT AMT ASC'
   goto OrderByRightAmtA

if @ord = '17. RIGHT AMT DESC'
   goto OrderByRightAmtD


OrderByCategory:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by f_invtyp_c
        , f_invtypnm_x
end
   goto ENDIT    


OrderByAmtA:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 8 asc     
end
   goto ENDIT    


OrderByAmtD:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 8 desc    
end
   goto ENDIT    


OrderByQtyA:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 7 asc
end
   goto ENDIT    

OrderByQtyD:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 7 desc
end
   goto ENDIT    


OrderByAmtPctA:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 10 asc
end
   goto ENDIT    


OrderByAmtPctD:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 10 desc
end
   goto ENDIT    


OrderByQtyPctA:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 9 asc
end
   goto ENDIT    


OrderByQtyPctD:

begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 9 desc
end
   goto ENDIT    


OrderByLeftQtyA:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 3
end
   goto ENDIT    


OrderByLeftQtyD:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 3 desc
end
   goto ENDIT    


OrderByLeftAmtA:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 4
end
   goto ENDIT    


OrderByLeftAmtD:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 4 desc
end
   goto ENDIT    


OrderByRightQtyA:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 5
end
   goto ENDIT    


OrderByRightQtyD:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 5 desc
end
   goto ENDIT    


OrderByRightAmtA:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 6
end
   goto ENDIT    


OrderByRightAmtD:
begin
select f_invtyp_c  
     , f_invtypnm_x
     , f_inv1_q 
     , f_inv1_a
     , f_inv2_q
     , f_inv2_a
     , f_inv3_q
     , f_inv3_a
     , f_inv4_q
     , f_inv4_a
  from d280db1.dbo.t280rpt
 where f_prof_x = @prof
   and a_uid_c  = @user
   and((@exp = '01. None')	
    or (@exp = '02. IMPACT QTY > ?'   and f_inv3_q > @amt)
    or (@exp = '03. IMPACT AMT > ?'   and f_inv3_a > @amt)
    or (@exp = '04. IMPACT QTY % > ?' and f_inv4_q > @amt)
    or (@exp = '05. IMPACT AMT % > ?' and f_inv4_a > @amt)
    or (@exp = '06. LEFT QTY > ?'     and f_inv1_q > @amt)
    or (@exp = '07. LEFT AMT > ?'     and f_inv1_a > @amt)
    or (@exp = '08. RIGHT QTY > ?'    and f_inv2_q > @amt)
    or (@exp = '09. RIGHT AMT > ?'    and f_inv2_a > @amt)
    or (@exp = '10. IMPACT QTY < ?'   and f_inv3_q < @amt)
    or (@exp = '11. IMPACT AMT < ?'   and f_inv3_a < @amt)
    or (@exp = '12. IMPACT QTY % < ?' and f_inv4_q < @amt)
    or (@exp = '13. IMPACT AMT % < ?' and f_inv4_a < @amt)
    or (@exp = '14. LEFT QTY < ?'     and f_inv1_q < @amt)
    or (@exp = '15. LEFT AMT < ?'     and f_inv1_a < @amt)
    or (@exp = '16. RIGHT QTY < ?'    and f_inv2_q < @amt)
    or (@exp = '17. RIGHT AMT < ?'    and f_inv2_a < @amt))
            
 order by 6 desc
end
   goto ENDIT    


ENDIT: 

/************************************************************************
   Return to the calling environment
 ************************************************************************/

return ( 0 )

go
