Friday, November 6, 2009

Code to move Work history to work orders

Here is the package to move all the history to work orders. This only will work for version 1.8.1.1

I used Toad SGA to extract these.

create or replace package xx_move_WO_from_WH
as

procedure move_wo(iPlant varchar2, iWork_order_number varchar2);

end;
/

create or replace package body xx_move_WO_from_WH
as

procedure move_wo(iPlant varchar2, iWork_order_number varchar2)
is


begin

INSERT INTO sa_work_order_task_cu
(plant, work_order_no, work_order_task_no,
accounting_treatment_type, usage_code, cu_no, cu_qty,
cu_estimate, unit_of_measure, cu_function, difficulty,
cu_actual_qty, standard_price_ind, discount_percent,
discount_amount, created_date, created_by, last_update_date,
last_update_user)
SELECT plant, work_order_no, work_order_task_no, accounting_treatment_type,
usage_code, cu_no, cu_qty, cu_estimate, unit_of_measure,
cu_function, difficulty, cu_actual_qty, standard_price_ind,
discount_percent, discount_amount, SYSDATE, USER, SYSDATE, USER
FROM sa_work_history_task_cu
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_attachment
(plant, work_order_no, work_order_task_no, attachment,
attachment_id, print_ind, attachment_revision_no)
SELECT plant, work_order_no, work_order_task_no, attachment, attachment_id,
print_ind, attachment_revision_no
FROM sa_work_history_attachment
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_work_order
(plant, work_order_no, work_class, work_type, asset_id,
asset_record_type, work_status, work_desc, asset_desc,
project_id, subproject_id, task_priority_default,
planned_total_amount, approved_amount, work_schedule_date,
work_entered_date, requestor_name, routing_list_id,
work_required_date, maintenance_manager, production_approver,
maintenance_approver, work_status_date, work_category,
benchmark_no, planner, pm_master_no, last_update_date,
safety_notes_ind, inspection_ind, lead_crew,
original_work_order_no, component_id, component_id_desc,
department, area, account_no, process_no, deficiency_tag,
building, LOCATION, POSITION, meter_units, meter_reading_last,
meter_reading_current, meter_ltd, vehicle_in_date,
vehicle_out_date, operator_id, shop, track_downtime_ind,
job_code, work_priority_total, work_priority_adjustment,
criticality, deliver_to_desc, work_form, meter_reading_date,
blanket_contract_no, sent_offsite_date, return_from_offsite_date,
blanket_revision_no, created_date, created_by, last_update_user,
signoff_by, signoff_date, actual_duration, actual_start_date,
actual_finish_date, finished_date, finished_by, closed_date,
closed_by, retain_type, retain_days, operational_reading_date,
asset_activity_log_no)
SELECT plant, work_order_no, work_class, work_type, asset_id,
asset_record_type, 'CLOSED', work_desc, asset_desc, project_id,
subproject_id, task_priority_default, planned_total_amount,
approved_amount, work_schedule_date, work_entered_date,
requestor_name, routing_list_id, work_required_date,
maintenance_manager, production_approver, maintenance_approver,
work_status_date, work_category, benchmark_no, planner,
pm_master_no, last_update_date, safety_notes_ind, inspection_ind,
lead_crew, original_work_order_no, component_id, component_id_desc,
department, area, account_no, process_no, deficiency_tag, building,
LOCATION, POSITION, meter_units, meter_reading_last,
meter_reading_current, meter_ltd, vehicle_in_date, vehicle_out_date,
operator_id, shop, track_downtime_ind, job_code,
work_priority_total, work_priority_adjustment, criticality,
deliver_to_desc, work_form, meter_reading_date, blanket_contract_no,
sent_offsite_date, return_from_offsite_date, blanket_revision_no,
created_date, created_by, last_update_user, signoff_by,
signoff_date, actual_duration, actual_start_date,
actual_finish_date, finished_date, finished_by, closed_date,
closed_by, retain_type, retain_days, operational_reading_date,
asset_activity_log_no
FROM sa_work_history
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_task
(plant, work_order_no, work_order_task_no, backlog_group,
task_status, task_status_date, task_desc, weekly_schedule_ind,
weekly_schedule_date, asset_record_type, process_no, asset_id,
downtime_ind, downtime_hours, assigned_to_name,
task_priority_total, task_priority_adjustment, task_priority,
criticality, account_no, specification_no,
specification_category, specification_type, asset_desc,
component_id_desc, daily_schedule_ind, daily_schedule_date, area,
department, bom_id, last_update_date, crew,
task_estimated_start_date, held_for_parts_ind, component_id,
estimated_duration_units, task_scheduled_shift,
task_required_date, estimated_duration, deliver_to_desc,
task_sequence_no, component_spec_no, component_spec_type,
component_spec_category, component_bom_id, work_request_no,
downtime_type, report_code1, report_code2, report_code3,
report_code4, report_code5, LOCATION, last_update_user, building,
POSITION, deficiency_tag, creation_date, work_code,
task_estimated_finish_date, job_code, created_by,
actual_duration, work_location, travel_time, work_trip,
actual_start_date, actual_finish_date, finished_date,
finished_by, type_of_work, type_of_work_units,
type_of_work_amount, comments, change_request_ind,
change_request_no, wbs, service_request_no, number_prefix,
street_number, number_suffix, street_name, street_direction,
cross_street, city, state_province, postal_code, offset,
direction, from_asset_record_type, to_asset_record_type,
from_asset_id, to_asset_id, point_id, iso_ind, environmental_ind,
run_to_failure_ind, health_ind, safety_critical_ind, task_phase,
planner, renewal_work_ind, street_number_char, shop, meter_units,
meter_ltd, meter_reading_current, job_reason_code,
job_action_code, vehicle_system_code, vehicle_assembly_code,
vehicle_component_code, asset_posted_date, asset_posted_ind,
mwm_field_order_no, mwm_order_type, sent_to_mwm_ind)
SELECT plant, work_order_no, work_order_task_no, backlog_group,
task_status, task_status_date, task_desc, weekly_schedule_ind,
weekly_schedule_date, asset_record_type, process_no, asset_id,
downtime_ind, downtime_hours, assigned_to_name, task_priority_total,
task_priority_adjustment, task_priority, criticality, account_no,
specification_no, specification_category, specification_type,
asset_desc, component_id_desc, daily_schedule_ind,
daily_schedule_date, area, department, bom_id, last_update_date,
crew, task_estimated_start_date, held_for_parts_ind, component_id,
estimated_duration_units, task_scheduled_shift, task_required_date,
estimated_duration, deliver_to_desc, task_sequence_no,
component_spec_no, component_spec_type, component_spec_category,
component_bom_id, work_request_no, downtime_type, report_code1,
report_code2, report_code3, report_code4, report_code5, LOCATION,
last_update_user, building, POSITION, deficiency_tag, creation_date,
work_code, task_estimated_finish_date, job_code, created_by,
actual_duration, work_location, travel_time, work_trip,
actual_start_date, actual_finish_date, finished_date, finished_by,
type_of_work, type_of_work_units, type_of_work_amount, comments,
change_request_ind, change_request_no, wbs, service_request_no,
number_prefix, street_number, number_suffix, street_name,
street_direction, cross_street, city, state_province, postal_code,
offset, direction, from_asset_record_type, to_asset_record_type,
from_asset_id, to_asset_id, point_id, NVL (iso_ind, 'N'),
NVL (environmental_ind, 'N'), NVL (run_to_failure_ind, 'N'),
NVL (health_ind, 'N'), NVL (safety_critical_ind, 'N'), task_phase,
planner, renewal_work_ind, street_number_char, shop, meter_units,
meter_ltd, meter_reading_current, job_reason_code, job_action_code,
vehicle_system_code, vehicle_assembly_code, vehicle_component_code,
asset_posted_date, asset_posted_ind, mwm_field_order_no,
mwm_order_type, NVL (sent_to_mwm_ind, 'N')
FROM sa_work_history_task
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_approval
(plant, work_order_no, approval_title, username, approval_status,
approval_status_date, approval_amount, approval_comments)
SELECT plant, work_order_no, approval_title, username, approval_status,
approval_status_date, approval_amount, approval_comments
FROM sa_work_history_approval
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_location_wrksht
(plant, work_order_no, work_order_task_no, cu_location,
accounting_treatment_type, usage_code, cu_no, cu_qty,
cu_actual_qty, cu_estimate, unit_of_measure, cu_function,
difficulty, standard_price_ind, discount_percent,
discount_amount, created_date, created_by, last_update_date,
last_update_user, cu_qty_calculated, no_of_conductors)
SELECT plant, work_order_no, work_order_task_no, cu_location,
accounting_treatment_type, usage_code, cu_no, cu_qty, cu_actual_qty,
cu_estimate, unit_of_measure, cu_function, difficulty,
standard_price_ind, discount_percent, discount_amount, SYSDATE,
USER, SYSDATE, USER, cu_qty_calculated, no_of_conductors
FROM sa_work_history_locat_wrksht
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_material
(plant, work_order_no, work_order_task_no, item_sequence_no,
item_status, item_status_date, last_update_date, vendor_contact,
vendor_code, blanket_contract_no, item_required_date, unit_price,
po_no, unit_of_issue, item_desc, internal_committed_amount,
internal_committed_quantity, external_committed_amount,
external_committed_quantity, revised_estimate_amount,
accrued_amount, original_estimate_amount, actual_amount,
actual_quantity, accrued_quantity, revised_estimate_quantity,
original_estimate_quantity, component_id, stock_type, stock_code,
po_item_type, issued_to_date_quantity, storeroom,
requisition_originator, cost_category, routing_list_id,
requisition_item, po_item, requisition_no, buyer, vendor_name,
deliver_to_department, expense_code, expense_category,
credit_card_purchase_ind, credit_card_holder_name, created_date,
created_by, last_update_user, reported_used_quantity)
SELECT plant, work_order_no, work_order_task_no, item_sequence_no,
item_status, item_status_date, last_update_date, vendor_contact,
vendor_code, blanket_contract_no, item_required_date, unit_price,
po_no, unit_of_issue, item_desc, internal_committed_amount,
internal_committed_quantity, external_committed_amount,
external_committed_quantity, revised_estimate_amount,
accrued_amount, original_estimate_amount, actual_amount,
actual_quantity, accrued_quantity, revised_estimate_quantity,
original_estimate_quantity, component_id, stock_type, stock_code,
po_item_type, issued_to_date_quantity, storeroom,
requisition_originator, cost_category, routing_list_id,
requisition_item, po_item, requisition_no, buyer, vendor_name,
deliver_to_department, expense_code, expense_category,
credit_card_purchase_ind, credit_card_holder_name, created_date,
created_by, last_update_user, reported_used_quantity
FROM sa_work_history_material
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_work_order_labor
(plant, work_order_no, work_order_task_no, labor_sequence_no,
craft, craftsmen_quantity, expense_code, premium_expense_code,
original_estimate_amount, revised_estimate_amount,
internal_committed_amount, external_committed_amount,
actual_amount, actual_premium_amount, original_estimate_hours,
revised_estimate_hours, internal_committed_hours,
external_committed_hours, actual_hours, actual_premium_hours,
last_update_date, last_update_user, burden_regular_amount,
burden_premium_amount, burden_regular_expense_code,
burden_premium_expense_code, labor_duration)
SELECT plant, work_order_no, work_order_task_no, labor_sequence_no, craft,
craftsmen_quantity, expense_code, premium_expense_code,
original_estimate_amount, revised_estimate_amount,
internal_committed_amount, external_committed_amount, actual_amount,
actual_premium_amount, original_estimate_hours,
revised_estimate_hours, internal_committed_hours,
external_committed_hours, actual_hours, actual_premium_hours,
last_update_date, last_update_user, burden_regular_amount,
burden_premium_amount, burden_regular_expense_code,
burden_premium_expense_code, labor_duration
FROM sa_work_history_labor
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_requirement
(plant, work_order_no, work_order_task_no, item_sequence_no,
requirement_type, requirement_quantity, requirement_units,
requirement_standard_price, requirement_duration,
requirement_total_amount, original_estimate_qty,
original_estimate_amount, revised_estimate_qty,
revised_estimate_amount, committed_qty, committed_amount,
actual_qty, actual_amount, expense_code, created_date,
created_by, last_update_date, last_update_user)
SELECT r.plant, r.work_order_no, r.work_order_task_no, r.item_sequence_no,
r.requirement_type, r.requirement_quantity, r.requirement_units,
r.requirement_standard_price, r.requirement_duration,
r.requirement_total_amount, r.original_estimate_qty,
r.original_estimate_amount, r.revised_estimate_qty,
r.revised_estimate_amount, r.committed_qty, r.committed_amount,
r.actual_qty, r.actual_amount, r.expense_code, SYSDATE, USER,
SYSDATE, USER
FROM sa_work_history_requirement r
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_task_cu_items
(plant, item_sequence_no, work_order_no, work_order_task_no,
accounting_treatment_type, item_type, item_id, storeroom,
item_qty, unit_of_measure, detail_sequence_no, item_duration,
unit_price, expense_code, premium_expense_code, created_date,
created_by, last_update_date, last_update_user, item_desc)
SELECT plant, item_sequence_no, work_order_no, work_order_task_no,
accounting_treatment_type, item_type, item_id, storeroom, item_qty,
unit_of_measure, detail_sequence_no, item_duration, unit_price,
expense_code, premium_expense_code, SYSDATE, USER, SYSDATE, USER,
item_desc
FROM sa_work_history_task_cu_itm
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_reg_acct_dist
(plant, work_order_no, work_order_task_no, regulatory_account_no,
regulatory_account_desc, calculated_percent_split,
override_percent_split, wip_account_no, regulatory_account_type,
direct_oh_percent_split, cu_estimate_total, created_date,
created_by, last_update_date, last_update_user)
SELECT plant, work_order_no, work_order_task_no, regulatory_account_no,
regulatory_account_desc, calculated_percent_split,
override_percent_split, wip_account_no, regulatory_account_type,
direct_oh_percent_split, cu_estimate_total, SYSDATE, USER, SYSDATE,
USER
FROM sa_work_history_reg_acct_dist
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_task_cu_bid
(plant, work_order_no, work_order_task_no, bid_date, cu_no,
contractor, bid_amount, material_ind, expense_code,
detail_sequence_no, labor_ind, created_date, created_by,
last_update_date, last_update_user, cu_function, difficulty)
SELECT plant, work_order_no, work_order_task_no, bid_date, cu_no,
contractor, bid_amount, material_ind, expense_code,
detail_sequence_no, labor_ind, SYSDATE, USER, SYSDATE, USER,
cu_function, difficulty
FROM sa_work_history_task_cu_bid
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_work_order_task_reg_acct_oh
(plant, work_order_no, work_order_task_no, overhead_class,
estimated_overhead_percent, applied_expense_category,
created_date, created_by, last_update_date, last_update_user)
SELECT plant, work_order_no, work_order_task_no, overhead_class,
estimated_overhead_percent, applied_expense_category, SYSDATE, USER,
SYSDATE, USER
FROM sa_work_history_reg_acct_oh
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_work_order_location
(plant, work_order_no, work_order_task_no, cu_location,
location_desc, attribute1, attribute2, attribute3, attribute4,
attribute5, attribute6, attribute7, attribute8, attribute9,
attribute10, created_date, created_by, last_update_date,
last_update_user, work_design_no, structure_type, SOURCE,
distance, distance_units, gis_gps_latitude, gis_gps_longitude,
overhead_ind, underground_ind)
SELECT plant, work_order_no, work_order_task_no, cu_location,
location_desc, attribute1, attribute2, attribute3, attribute4,
attribute5, attribute6, attribute7, attribute8, attribute9,
attribute10, SYSDATE, USER, SYSDATE, USER, work_design_no,
structure_type, SOURCE, distance, distance_units, gis_gps_latitude,
gis_gps_longitude, overhead_ind, underground_ind
FROM sa_work_history_location
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_fixed_asset
(plant, work_order_no, work_order_task_no, item_no, cu_no,
property_unit_no, cu_location, action, asset_record_type,
asset_id, action_date, regulatory_account_no,
regulatory_account_type, created_date, created_by,
last_update_date, last_update_user, asset_value, period_year,
apply_prior_year, contributed_ind, cu_function,
change_request_no, asset_change_seq_no, number_of_units)
SELECT a.plant, a.work_order_no, a.work_order_task_no, a.item_no, a.cu_no,
a.property_unit_no, a.cu_location, a.action, a.asset_record_type,
a.asset_id, a.action_date, a.regulatory_account_no,
a.regulatory_account_type, SYSDATE, USER, SYSDATE, USER,
a.asset_value, a.period_year, a.apply_prior_year, a.contributed_ind,
a.cu_function, a.change_request_no, a.asset_change_seq_no,
a.number_of_units
FROM sa_work_history_fixed_asset a
WHERE a.plant = iPlant
AND a.work_order_no = iWork_order_number
AND NVL (a.contributed_ind, 'N') = 'N';


INSERT INTO sa_work_order_adjustment
(plant, work_order_no, work_order_task_no, expense_code,
actual_amount, last_update_date)
SELECT plant, work_order_no, work_order_task_no, expense_code,
actual_amount, last_update_date
FROM sa_work_history_adjustment
WHERE plant = iPlant AND work_order_no = iWork_order_number;


UPDATE sa_work_order_material w
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1, attribute1
FROM sa_work_history_material r
WHERE r.plant = iPlant
AND r.work_order_no = iWork_order_number
AND r.work_order_task_no = w.work_order_task_no
AND r.item_sequence_no = w.item_sequence_no)
WHERE w.plant = iPlant AND w.work_order_no = iWork_order_number;

UPDATE sa_work_order
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1, attribute1
FROM sa_work_history
WHERE plant = iPlant AND work_order_no = iWork_order_number)
WHERE plant = iPlant AND work_order_no = iWork_order_number;

UPDATE sa_work_order_material w
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1
FROM sa_work_history_material r
WHERE r.plant = iPlant
AND r.work_order_no = iWork_order_number
AND r.work_order_task_no = w.work_order_task_no
AND r.item_sequence_no = w.item_sequence_no)
WHERE w.plant = iPlant AND w.work_order_no = iWork_order_number;

INSERT INTO sa_work_order_service_contract
(plant, work_order_no, work_order_task_no, labor_sequence_no,
service_contract_no, contract_revision_no, contract_item,
item_id, craftsmen_quantity, rate, rate_type, expense_code,
original_estimate_amount, revised_estimate_amount,
committed_amount, accrued_amount, actual_amount,
original_estimate_quantity, revised_estimate_quantity,
committed_quantity, accrued_quantity, actual_quantity,
last_update_date, last_update_user)
SELECT plant, work_order_no, work_order_task_no, labor_sequence_no,
service_contract_no, contract_revision_no, contract_item, item_id,
craftsmen_quantity, rate, rate_type, expense_code,
original_estimate_amount, revised_estimate_amount, committed_amount,
accrued_amount, actual_amount, original_estimate_quantity,
revised_estimate_quantity, committed_quantity, accrued_quantity,
actual_quantity, last_update_date, last_update_user
FROM sa_work_history_contract
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_work_order_task_asset_list
(work_order_no, work_order_task_no, sequence_no, plant,
asset_record_type, asset_id, component_id, percent_split,
total_amount, created_date, created_by, last_update_date,
last_update_user)
SELECT work_order_no, work_order_task_no, sequence_no, plant,
asset_record_type, asset_id, component_id, percent_split,
total_amount, created_date, created_by, last_update_date,
last_update_user
FROM sa_work_history_task_asset_lis
WHERE work_order_no = iWork_order_number AND plant = iPlant;

BEGIN
UPDATE sa_work_order_task w
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1
FROM sa_work_history_task r
WHERE r.plant = iPlant
AND r.work_order_no = iWork_order_number
AND r.work_order_task_no = w.work_order_task_no)
WHERE w.plant = iPlant AND w.work_order_no = iWork_order_number;
END;

INSERT INTO sa_work_order_permit
(plant, work_order_no, work_order_task_no, permit_type, permit_no,
permit_acquired_date, last_update_date, created_date, created_by,
last_update_user, attribute1, attribute2, attribute3, attribute4,
attribute5, attribute6, attribute7, attribute8, attribute9,
attribute10, permit_template_id, asset_record_type, asset_id)
SELECT plant, work_order_no, work_order_task_no, permit_type, permit_no,
permit_acquired_date, last_update_date, created_date, created_by,
last_update_user, attribute1, attribute2, attribute3, attribute4,
attribute5, attribute6, attribute7, attribute8, attribute9,
attribute10, permit_template_id, asset_record_type, asset_id
FROM sa_work_history_permit
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_service_history_data
(plant, work_order_no, work_order_task_no, cu_location,
specification_type, specification_category)
SELECT plant, work_order_no, work_order_task_no, cu_location,
specification_type, specification_category
FROM sa_work_history_service_data
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_service_history_details
(plant, work_order_no, work_order_task_no, specification_type,
specification_category, attribute_sequence_no, attribute_value,
attribute_desc)
SELECT plant, work_order_no, work_order_task_no, specification_type,
specification_category, attribute_sequence_no, attribute_value,
attribute_desc
FROM sa_work_history_service_detail
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_work_material_attachment
(plant, work_order_no, work_order_task_no, item_sequence_no,
attachment, attachment_id, copy_to_purchase_order, print_ind,
last_update_date, last_update_user, created_date, created_by,
attachment_revision_no)
SELECT plant, work_order_no, work_order_task_no, item_sequence_no,
attachment, attachment_id, copy_to_purchase_order, print_ind,
SYSDATE, USER, SYSDATE, USER, attachment_revision_no
FROM sa_work_history_mtl_attch
WHERE plant = iPlant AND work_order_no = iWork_order_number;

INSERT INTO sa_work_order_task_failure
(plant, work_order_no, work_order_task_no, asset_id,
asset_record_type, component_id, failure_code, repair_code,
component_code, primary_ind, failure_mode, root_cause,
work_request_no, further_action, further_action_desc,
further_action_required_date, last_update_date, last_update_user,
created_date, created_by, sequence_no)
SELECT plant, work_order_no, work_order_task_no, asset_id,
asset_record_type, component_id, failure_code, repair_code,
component_code, primary_ind, failure_mode, root_cause,
work_request_no, further_action, further_action_desc,
further_action_required_date, last_update_date, last_update_user,
created_date, created_by, sequence_no
FROM sa_work_order_task_failure
WHERE plant = iPlant AND work_order_no = iWork_order_number;


UPDATE sa_work_order
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1
FROM sa_work_history
WHERE plant = iPlant AND work_order_no = iWork_order_number)
WHERE plant = iPlant AND work_order_no = iWork_order_number;


UPDATE sa_work_order_task w
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1, attribute1
FROM sa_work_history_task r
WHERE r.plant = iPlant
AND r.work_order_no = iWork_order_number
AND r.work_order_task_no = w.work_order_task_no)
WHERE w.plant = iPlant AND w.work_order_no = iWork_order_number;

UPDATE sa_work_order_permit w
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1
FROM sa_work_history_permit r
WHERE r.plant = iPlant
AND r.work_order_no = iWork_order_number
AND r.work_order_task_no = w.work_order_task_no)
WHERE w.plant = iPlant AND w.work_order_no = iWork_order_number;

UPDATE sa_work_order_permit w
SET (attribute1, attribute2, attribute3, attribute4, attribute5,
attribute6, attribute7, attribute8, attribute9, attribute10) =
(SELECT attribute1, attribute1, attribute1, attribute1, attribute1,
attribute1, attribute1, attribute1, attribute1, attribute1
FROM sa_work_history_permit r
WHERE r.plant = iPlant
AND r.work_order_no = iWork_order_number
AND r.work_order_task_no = w.work_order_task_no)
WHERE w.plant = iPlant AND w.work_order_no = iWork_order_number;


DELETE FROM sa_work_history_task_cu
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_reg_acct_dist
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_labor
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_material
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_mtl_notes
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_permit
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_service_detail
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_locat_wrksht
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_task_failure
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_service_data
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_task_cu_bid
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_location
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_reg_acct_oh
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_task_cu_itm
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_task_notes
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_task_assig
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history_requirement
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_fixed_asset
WHERE plant = iPlant AND work_order_no = iWork_order_number
AND NVL (contributed_ind, 'N') = 'N';

DELETE FROM sa_asset_work_history
WHERE plant = iPlant AND work_order_no = iWork_order_number;


INSERT INTO sa_crew_work_log
(plant, crew, work_order_no, work_order_task_no, backlog_group,
event_type, event_date, event_desc, reported_by,
last_update_date, last_update_user, created_date, created_by)
SELECT plant, crew, work_order_no, work_order_task_no, backlog_group,
event_type, event_date, event_desc, reported_by, last_update_date,
last_update_user, created_date, created_by
FROM sa_crew_history_log
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_approval
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_attachment
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_notes
WHERE plant = iPlant AND work_order_no = iWork_order_number;

DELETE FROM sa_work_history
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_crew_history_log
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_adjustment
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_task_asset_lis
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_contract
WHERE plant = iPlant AND work_order_no = iWork_order_number;


DELETE FROM sa_work_history_task
WHERE plant = iPlant AND work_order_no = iWork_order_number;


commit;

end;

end;

No comments:

Post a Comment