Monday, 31 October 2011

req_distribution

SELECT DISTINCT
        prh.REQUISITION_HEADER_ID,
        prd.distribution_id,
        prd.requisition_line_id,       
        PRH.segment1 D_REFERENCE_NUM,
        prd.distribution_num D_DISTRIBUTION_NUM,
        msi.segment1 D_ITEM,
        (SELECT concatenated_segments
           FROM gl_code_combinations_kfv
          WHERE code_combination_id = prd.code_combination_id) D_CHARGE_ACCOUNT,
        prd.req_line_quantity,
        prd.attribute1,
        prd.attribute2,
        prd.attribute3,
        prd.attribute4,
        prd.attribute5               
from
        po.po_requisition_headers_all prh,
        po.po_requisition_lines_all prl,
        apps.per_people_f ppf1,
        (select distinct agent_id,agent_name from apps.po_agents_v ) ppf2,
        po.po_req_distributions_all prd,
        inv.mtl_system_items_b msi,
        org_organization_definitions ood
WHERE
        prh.requisition_header_id = prl.requisition_header_id
        and prl.requisition_line_id = prd.requisition_line_id
        and ppf1.person_id = prh.preparer_id
        and prh.creation_date between ppf1.effective_start_date and ppf1.effective_end_date
        and ppf2.agent_id(+) = msi.buyer_id
        and msi.inventory_item_id = prl.item_id
        and msi.organization_id = prl.destination_organization_id
        AND trunc(prh.creation_date) between '01-Aug-2011' and '13-Aug-2011'
        AND prh.org_id = ood.operating_unit       
        AND (prh.CLOSED_CODE NOT IN 'FINALLY CLOSED'
        AND prh.CLOSED_CODE NOT IN 'CLOSED'
        AND prh.closed_code NOT in 'CLOSE'
        OR prh.closed_code is null )
        AND ood.set_of_books_id = 5
ORDER BY 1,2

No comments:

Post a Comment