Sunday, 29 July 2012

OM Sales order query in oracle apps

SELECT
      H.ORDER_NUMBER,
      PARTY.PARTY_NAME CUSTOMER_NAME,
      OT.NAME ORDER_TYPE,
      CUST_ACCT.ACCOUNT_NUMBER CUSTOMER_NUMBER,
      H.CUST_PO_NUMBER,
      H.ORDERED_DATE,
      DECODE (SOLD_ARL.MEANING, NULL, NULL, ' ' || SOLD_ARL.MEANING)
                                                              SOLD_TO_CONTACT,
      PL.NAME PRICE_LIST,
      H.BLANKET_NUMBER,
      H.SALESREP_ID,  -----NO NAME AVAILABLE ONLY ID
      SHIP_SU.LOCATION SHIP_TO_LOCATION,
      SHIP_LOC.ADDRESS1 SHIP_TO_ADDRESS1,
      DECODE (SHIP_LOC.COUNTRY, NULL, NULL, SHIP_LOC.COUNTRY)
                                          SHIP_TO_ADDRESS5,
      BILL_SU.LOCATION INVOICE_TO_LOCATION,
      BILL_LOC.ADDRESS1 INVOICE_TO_ADDRESS1,
      BILL_LOC.ADDRESS2 INVOICE_TO_ADDRESS2,
      DECODE (BILL_LOC.COUNTRY, NULL, NULL, BILL_LOC.COUNTRY)
                                                          INVOICE_TO_ADDRESS5,
      H.FLOW_STATUS_CODE,
      H.TRANSACTIONAL_CURR_CODE,
      L.LINE_NUMBER,
      L.ORDERED_ITEM,
      L.ORDERED_QUANTITY,
      SHIP_FROM_ORG.ORGANIZATION_CODE SHIP_FROM,
      L.SOURCE_TYPE_CODE,
      L.SCHEDULE_SHIP_DATE,
      L.SCHEDULE_ARRIVAL_DATE,
      L.REQUEST_DATE,
      L.PROMISE_DATE,
      L.ORDERED_QUANTITY,
      L.SHIPPING_METHOD_CODE,
      L.FREIGHT_TERMS_CODE,
      PARTY.PARTY_NAME SOLD_TO
FROM
    OE_ORDER_HEADERS_ALL H,
    HZ_PARTIES PARTY,
    HZ_CUST_ACCOUNTS CUST_ACCT,
    OE_TRANSACTION_TYPES_TL OT,
    AR_LOOKUPS SOLD_ARL,
    HZ_PARTIES SOLD_PARTY,
    HZ_RELATIONSHIPS SOLD_REL,
    HZ_CUST_ACCOUNTS SOLD_ACCT,
    HZ_CUST_ACCOUNT_ROLES SOLD_ROLES,
    QP_LIST_HEADERS_TL PL,
    HZ_CUST_SITE_USES_ALL SHIP_SU,
    HZ_CUST_ACCT_SITES_ALL SHIP_CAS,
    HZ_LOCATIONS SHIP_LOC,
    HZ_PARTY_SITES SHIP_PS,
    HZ_CUST_SITE_USES_ALL BILL_SU,
    HZ_CUST_ACCT_SITES_ALL BILL_CAS,
    HZ_LOCATIONS BILL_LOC,
    HZ_PARTY_SITES BILL_PS,
    -----------------------
    OE_ORDER_LINES_ALL L,
    MTL_PARAMETERS SHIP_FROM_ORG,
    AR_LOOKUPS SHIP_ARL,
    ----------------------
    HZ_PARTIES SHIP_PARTY,
    HZ_CUST_ACCOUNTS SHIP_ACCT,
    HZ_RELATIONSHIPS SHIP_REL,
    HZ_CUST_ACCOUNT_ROLES SHIP_ROLES
WHERE
    H.ORDER_NUMBER=66404
    AND H.SOLD_TO_ORG_ID = CUST_ACCT.CUST_ACCOUNT_ID
    AND CUST_ACCT.PARTY_ID = PARTY.PARTY_ID
    --------------------------------------------
    AND  H.ORDER_TYPE_ID = OT.TRANSACTION_TYPE_ID
    --------------------------------------------
    AND H.SOLD_TO_CONTACT_ID = SOLD_ROLES.CUST_ACCOUNT_ROLE_ID(+)
    AND SOLD_ROLES.PARTY_ID = SOLD_REL.PARTY_ID(+)
    AND SOLD_ROLES.ROLE_TYPE(+) = 'CONTACT'
    AND SOLD_ROLES.CUST_ACCOUNT_ID = SOLD_ACCT.CUST_ACCOUNT_ID(+)
    AND NVL (SOLD_REL.OBJECT_ID, -1) = NVL (SOLD_ACCT.PARTY_ID, -1)
    AND SOLD_REL.SUBJECT_ID = SOLD_PARTY.PARTY_ID(+)
    AND SOLD_ARL.LOOKUP_TYPE(+) = 'CONTACT_TITLE'
    AND SOLD_ARL.LOOKUP_CODE(+) = SOLD_PARTY.PERSON_PRE_NAME_ADJUNCT
    ------------------------------------------------------------------
    AND H.PRICE_LIST_ID = PL.LIST_HEADER_ID(+)
    AND PL.LANGUAGE(+) = USERENV ('LANG')
    ----------------------------------------------------------
    AND H.SHIP_TO_ORG_ID = SHIP_SU.SITE_USE_ID(+)
    AND SHIP_SU.CUST_ACCT_SITE_ID = SHIP_CAS.CUST_ACCT_SITE_ID(+)
    --------------------------------------------------------------
    AND H.SHIP_TO_ORG_ID = SHIP_SU.SITE_USE_ID
    AND SHIP_SU.CUST_ACCT_SITE_ID = SHIP_CAS.CUST_ACCT_SITE_ID
    AND SHIP_CAS.PARTY_SITE_ID = SHIP_PS.PARTY_SITE_ID
    AND SHIP_LOC.LOCATION_ID = SHIP_PS.LOCATION_ID
    -------------------------------------------------------
    AND H.INVOICE_TO_ORG_ID = BILL_SU.SITE_USE_ID(+)
    AND BILL_SU.CUST_ACCT_SITE_ID = BILL_CAS.CUST_ACCT_SITE_ID(+)
    --------------------------------------------------------------
    AND H.INVOICE_TO_ORG_ID = BILL_SU.SITE_USE_ID(+)
    AND BILL_SU.CUST_ACCT_SITE_ID = BILL_CAS.CUST_ACCT_SITE_ID(+)
    AND BILL_CAS.PARTY_SITE_ID = BILL_PS.PARTY_SITE_ID(+)
    AND BILL_LOC.LOCATION_ID(+) = BILL_PS.LOCATION_ID
    --------------------------------------------------
    -------------------------------------------------
    AND L.HEADER_ID = H.HEADER_ID
    -------------------------------------------------
    AND L.SOLD_TO_ORG_ID = CUST_ACCT.CUST_ACCOUNT_ID(+)
    AND CUST_ACCT.PARTY_ID = PARTY.PARTY_ID(+)
    AND L.SHIP_FROM_ORG_ID = SHIP_FROM_ORG.ORGANIZATION_ID(+)
    ---------------------------------------------------------
    AND L.SHIP_TO_CONTACT_ID = SHIP_ROLES.CUST_ACCOUNT_ROLE_ID(+)
    AND SHIP_ROLES.PARTY_ID = SHIP_REL.PARTY_ID(+)
    AND SHIP_ROLES.ROLE_TYPE(+) = 'CONTACT'
    AND SHIP_REL.SUBJECT_ID = SHIP_PARTY.PARTY_ID(+)
    AND SHIP_ROLES.CUST_ACCOUNT_ID = SHIP_ACCT.CUST_ACCOUNT_ID(+)
    AND NVL (SHIP_REL.OBJECT_ID, -1) = NVL (SHIP_ACCT.PARTY_ID, -1)
    AND SHIP_ARL.LOOKUP_TYPE(+) = 'CONTACT_TITLE'
    AND SHIP_ARL.LOOKUP_CODE(+) = SHIP_PARTY.PERSON_PRE_NAME_ADJUNCT

No comments:

Post a Comment