<?xml version="1.0"?>
<select db="prod">
        object.object_id object_id
  ,reg_date.registration_date registration
  ,object.type_description type
  ,object.version
  ,decode(object.faulty,'F','   ','T','bad') as "Status"
  ,object.center center
  ,GantryVal.Gantryval_val Gantry
  ,ModBond.Modbond_val bonding
  ,ModValidation.ModValidation_val validation
  ,barat.description, barat.diagnostic, barat.special, barat.repairbase
 from
 (select OA.object_id, OA.object, OA.type, OD.description,
         OD.version, OD.version_description, OD.type_description,
         H.center, H.faulty, H.current_action as Last_action
  from
  (select object_id, max(history_id) S
          from history
          group by object_id) D,
   object_assembly OA,
   object_description OD,
   history H
  where D.object_id = OA.object_id
    and OA.object = OD.object
    and OA.type = OD.type
    and OA.version = OD.version
    and OA.object='MOD'
    and OA.type LIKE '2.%'
    and OA.container_id is null
    and H.object_id = D.object_id
    and H.history_id = D.S
    and H.center='center_name_to_be_replaced'
 ) object
 ,
  (select object_id, to_char(sequence,'DD-Mon-YYYY') as registration_date
     from history
     where current_action = 'Registration'
       and transfer_id is null
     group by object_id, sequence
 ) reg_date
 ,
   (select C.object_id, C.Gantryval_val
           , M1.Sensassemb_val
           , M2.Hybassemb_val
           , M3.Sensposcheck1_val
           , M4.Hybposcheck1_val
           , M5.Gluemonitoring_val
           , M6.Sensposcheck2_val
           , M7.Hybposcheck2_val
      from
        Gantryval_1_mod_ C,
        Sensassemb_1_mod_ M1,
        Hybassemb_1_mod_ M2,
        Sensposcheck1_1_mod_ M3,
        Hybposcheck1_1_mod_ M4,
        Gluemonitoring_1_mod_ M5,
        Sensposcheck2_1_mod_ M6,
        Hybposcheck2_1_mod_ M7
     where C.Sensassemb_1_mod_ = M1.test_id
       and C.Hybassemb_1_mod_ = M2.test_id
       and C.Sensposcheck1_1_mod_ = M3.test_id
       and C.Hybposcheck1_1_mod_ = M4.test_id
       and C.Gluemonitoring_1_mod_ = M5.test_id
       and C.Sensposcheck2_1_mod_ = M6.test_id
       and C.Hybposcheck2_1_mod_ = M7.test_id
   ) GantryVal
 ,
   (select C.object_id, C.Modbond_val
           , M1.Prebond_val, M1.center
           , M2.Bondmachine_val, M3.Bondwire_val
           , M4.Bondlog_val, M5.Bondstatus_val
           , M6.Postbond_val, M7.Bondrep_val
      from
        Modbond_1_mod_ C,
        Prebond_1_mod_ M1,
        Bondmachine_1_mod_ M2,
        Bondwire_1_mod_ M3,
        Bondlog_1_mod_ M4,
        Bondstatus_1_mod_ M5,
        Postbond_1_mod_ M6,
        Bondrep_1_mod_ M7
     where C.Prebond_1_mod_ = M1.test_id
       and C.Bondmachine_1_mod_ = M2.test_id
       and C.Bondwire_1_mod_ = M3.test_id
       and C.Bondlog_1_mod_ = M4.test_id
       and C.Bondstatus_1_mod_ = M5.test_id
       and C.Postbond_1_mod_ = M6.test_id
       and C.Bondrep_1_mod_ = M7.test_id
   ) ModBond
 ,
   (select C.object_id, C.ModValidation_val
           , M.ModulBasic_val
      from
        ModValidation_2_mod_ C,
        ModulBasic_2_mod_ M
     where C.ModulBasic_2_mod_ = M.test_id
   ) ModValidation
    ,
( select known_prob.object_id, known_prob.description, Fault.diagnostic
         , special.special, repair.repairbase
  from
(select kp.object_id, kp.problem_id, pd.description
  from
     known_problem kp,
     problem_description pd
    where kp.problem_id = pd.problem_id
) known_prob
  ,
 ( select C.object_id, M.hybfaultiness_val fault, DD.diagnostic
 from
   hybfaultinessComp_1_hyb_ C,
   hybfaultiness_1_hyb_ M,
   diagnostic_description DD
 where C.hybfaultiness_1_hyb_ = M.test_id
   and DD.action = 'HYBFautltiness'
   and instr(M.HYBFaultiness_val,':'||to_char(DD.code)||':') != 0
 ) Fault
  ,
 (select C.object_id, C.special_val, C.freeaction_val, M.special
    from
      freeaction_1_hyb_ C,
      special_1_hyb_ M
    where C.special_1_hyb_ = M.test_id
      and instr(M.special,'040226') = 0
  ) special
  ,
 (select C.object_id, C.repair_val, M.repairbase_val, M.repairbase
    from
      repair_1_hyb_ C,
      repairbase_1_hyb_ M
    where C.repairbase_1_hyb_ = M.test_id
  ) repair
  where known_prob.object_id = Fault.object_id (+)
    and known_prob.object_id = special.object_id (+)
    and known_prob.object_id = repair.object_id (+)
) barat
  where object.object='MOD'
    and object.object_id = reg_date.object_id(+)
    and object.object_id = gantryval.object_id(+)
    and object.object_id = modbond.object_id(+)
    and object.object_id = modvalidation.object_id(+)
    and object.object_id = barat.object_id(+)
  order by substr( to_char( object.object_id), 7, 8)
</select>

