Wednesday, 19 February 2014

SQL Query Supplier Details

SELECT *
FROM (
  (SELECT POV.VENDOR_ID VENDOR_ID,
    POV.VENDOR_NAME SUPPLIER_NAME ,
    POV.SEGMENT1 SUPPLIER_NUMBER ,
    POV.VENDOR_NAME_ALT ALTERNAETE_NAME ,
    POV.VAT_REGISTRATION_NUM TAX_REGISTRATION_NUMBER ,
    POV.ATTRIBUTE3 VENDOR_TYPE ,
    PLC.DISPLAYED_FIELD SUPPLIER_TYPE ,
    POVSA.VENDOR_SITE_CODE SITE_NAME ,
    FT.TERRITORY_SHORT_NAME COUNTRY ,
    POVSA.ADDRESS_LINE1 ADDRESS_LINE1 ,
    POVSA.ADDRESS_LINE2 ADDRESS_LINE2 ,
    POVSA.ADDRESS_LINE3 ADDRESS_LINE3 ,
    POVSA.ADDRESS_LINE4 ADDRESS_LINE4 ,
    POVSA.CITY CITY ,
    POVSA.STATE STATE ,
    POVSA.ZIP POSTAL_CODE ,
    POVSA.PROVINCE PROVINCE ,
    POVSA.COUNTY COUNTY ,
    POVSA.LANGUAGE LANGUAGE ,
    POVSA.PHONE COMMUNICATION_VOICE ,
    POVSA.FAX COMMUNICATION_FAX ,
    POVSA.EMAIL_ADDRESS COMMUNICATION_EMAIL ,
    POVC.LAST_NAME CONTACT_NAME ,
    POVC.PHONE CONTACT_TELEPHONE ,
    POVC.FAX CONTACT_FAX ,
    POVC.EMAIL_ADDRESS CONTACT_EMAIL ,
    GCC.SEGMENT1
    ||'-'
    ||GCC.SEGMENT2
    ||'-'
    ||GCC.SEGMENT3
    ||'-'
    ||GCC.SEGMENT4
    ||'-'
    ||GCC.SEGMENT5
    ||'-'
    ||GCC.SEGMENT6
    ||'-'
    ||GCC.SEGMENT7
    ||'-'
    ||GCC.SEGMENT8
    ||'-'
    ||GCC.SEGMENT9
    ||'-'
    ||GCC.SEGMENT10 LIABILITY_ACCOUNT ,
    DECODE(POVSA.MATCH_OPTION,'P','Purchase Order','R','Receipt') INVOICE_MATCH_OPTION ,
    POVSA.HOLD_UNMATCHED_INVOICES_FLAG HOLD_UNMATCHED_INVOICE ,
    (SELECT APT.NAME
    FROM AP_TERMS_TL APT
    WHERE APT.TERM_ID = POVSA.TERMS_ID
    AND APT.LANGUAGE  = 'US'
    )PAYMENT_TERMS ,
    POVSA.INVOICE_CURRENCY_CODE INVOICE_CURRENCY ,
    POVSA.PAYMENT_METHOD_LOOKUP_CODE PAYMENT_METHOD ,
    ABA.BANK_ACCOUNT_NAME BANK_ACCOUNT_NAME ,
    ABA.BANK_ACCOUNT_NUM BANK_ACCOUNT_NUMBER ,
    ABB.BANK_NAME BANK_NAME,
    ABB.BANK_NUMBER BANK_NUMBER,
    ABB.BANK_BRANCH_NAME BANK_BRANCH_NAME,
    ABB.BANK_NUM BANK_BRANCH_NUMBER,
    FTB.TERRITORY_SHORT_NAME BANK_COUNTRY,
    POVSA.VAT_CODE INVOICE_TAX_CODE ,
    POV.VAT_REGISTRATION_NUM TAX_REGISTRATION_NUMBER1 ,
    POVSA.TAX_REPORTING_SITE_FLAG INCOME_TAX_REPORTING_SITE ,
    HR_SHIPTO.LOCATION_CODE SHIP_TO_LOCATION ,
    HR_BILLTO.LOCATION_CODE BILL_TO_LOCATION,
    POV.CREATION_DATE CREATION_DATE,
    POV.CREATED_BY CREATED_BY,
    POV.LAST_UPDATE_DATE LAST_UPDATE_DATE,
    POV.LAST_UPDATED_BY LAST_UPDATED_BY,
    POV.LAST_UPDATE_LOGIN LAST_UPDATE_LOGIN
  FROM APPS.PO_VENDORS POV,
    APPS.PO_VENDOR_SITES_ALL POVSA ,
    APPS.FND_TERRITORIES_TL FT ,
    APPS.PO_VENDOR_CONTACTS POVC ,
    APPS.GL_CODE_COMBINATIONS GCC ,
    APPS.HR_LOCATIONS_ALL HR_SHIPTO ,
    APPS.HR_LOCATIONS_ALL HR_BILLTO ,
    APPS.PO_LOOKUP_CODES PLC ,
    APPS.AP_BANK_ACCOUNT_USES_ALL ABAU,
    APPS.AP_BANK_ACCOUNTS_ALL ABA,
    APPS.AP_BANK_BRANCHES ABB,
    APPS.FND_TERRITORIES_TL FTB
  WHERE POV.VENDOR_ID               = POVSA.VENDOR_ID
  AND FT.TERRITORY_CODE             = POVSA.COUNTRY
  AND FT.LANGUAGE                   = 'US'
  AND POVC.VENDOR_SITE_ID(+)        = POVSA.VENDOR_SITE_ID
  AND GCC.CODE_COMBINATION_ID       = POVSA.ACCTS_PAY_CODE_COMBINATION_ID
  AND HR_SHIPTO.LOCATION_ID(+)      = POVSA.SHIP_TO_LOCATION_ID
  AND HR_BILLTO.LOCATION_ID(+)      = POVSA.BILL_TO_LOCATION_ID
  AND PLC.LOOKUP_CODE(+)            = POV.VENDOR_TYPE_LOOKUP_CODE
  AND PLC.LOOKUP_TYPE(+)            = 'VENDOR TYPE'
  AND ABAU.VENDOR_ID                = POVSA.VENDOR_ID(+)
  AND ABAU.VENDOR_SITE_ID           = POVSA.VENDOR_SITE_ID(+)
  AND ABAU.EXTERNAL_BANK_ACCOUNT_ID = ABA.BANK_ACCOUNT_ID(+)
  AND ABA.BANK_BRANCH_ID            = ABB.BANK_BRANCH_ID
  AND FTB.TERRITORY_CODE(+)         = ABB.COUNTRY
  AND FTB.LANGUAGE(+)               = 'US'
  AND POVSA.ORG_ID                  = 2659
  )
UNION ALL
  (SELECT POV.VENDOR_ID VENDOR_ID,
    POV.VENDOR_NAME SUPPLIER_NAME ,
    POV.SEGMENT1 SUPPLIER_NUMBER ,
    POV.VENDOR_NAME_ALT ALTERNAETE_NAME ,
    POV.VAT_REGISTRATION_NUM TAX_REGISTRATION_NUMBER ,
    POV.ATTRIBUTE3 VENDOR_TYPE ,
    PLC.DISPLAYED_FIELD SUPPLIER_TYPE ,
    POVSA.VENDOR_SITE_CODE SITE_NAME ,
    FT.TERRITORY_SHORT_NAME COUNTRY ,
    POVSA.ADDRESS_LINE1 ADDRESS_LINE1 ,
    POVSA.ADDRESS_LINE2 ADDRESS_LINE2 ,
    POVSA.ADDRESS_LINE3 ADDRESS_LINE3 ,
    POVSA.ADDRESS_LINE4 ADDRESS_LINE4 ,
    POVSA.CITY CITY ,
    POVSA.STATE STATE ,
    POVSA.ZIP POSTAL_CODE ,
    POVSA.PROVINCE PROVINCE ,
    POVSA.COUNTY COUNTY ,
    POVSA.LANGUAGE LANGUAGE ,
    POVSA.PHONE COMMUNICATION_VOICE ,
    POVSA.FAX COMMUNICATION_FAX ,
    POVSA.EMAIL_ADDRESS COMMUNICATION_EMAIL ,
    POVC.LAST_NAME CONTACT_NAME ,
    POVC.PHONE CONTACT_TELEPHONE ,
    POVC.FAX CONTACT_FAX ,
    POVC.EMAIL_ADDRESS CONTACT_EMAIL ,
    GCC.SEGMENT1
    ||'-'
    ||GCC.SEGMENT2
    ||'-'
    ||GCC.SEGMENT3
    ||'-'
    ||GCC.SEGMENT4
    ||'-'
    ||GCC.SEGMENT5
    ||'-'
    ||GCC.SEGMENT6
    ||'-'
    ||GCC.SEGMENT7
    ||'-'
    ||GCC.SEGMENT8
    ||'-'
    ||GCC.SEGMENT9
    ||'-'
    ||GCC.SEGMENT10 LIABILITY_ACCOUNT ,
    DECODE(POVSA.MATCH_OPTION,'P','Purchase Order','R','Receipt') INVOICE_MATCH_OPTION ,
    POVSA.HOLD_UNMATCHED_INVOICES_FLAG HOLD_UNMATCHED_INVOICE ,
    (SELECT APT.NAME
    FROM AP_TERMS_TL APT
    WHERE APT.TERM_ID = POVSA.TERMS_ID
    AND APT.LANGUAGE  = 'US'
    )PAYMENT_TERMS ,
    POVSA.INVOICE_CURRENCY_CODE INVOICE_CURRENCY ,
    POVSA.PAYMENT_METHOD_LOOKUP_CODE PAYMENT_METHOD ,
    NULL BANK_ACCOUNT_NAME ,
    NULL BANK_ACCOUNT_NUMBER ,
    NULL BANK_NAME,
    NULL BANK_NUMBER,
    NULL BANK_BRANCH_NAME,
    NULL BANK_BRANCH_NUMBER,
    NULL BANK_COUNTRY,
    POVSA.VAT_CODE INVOICE_TAX_CODE ,
    POV.VAT_REGISTRATION_NUM TAX_REGISTRATION_NUMBER1 ,
    POVSA.TAX_REPORTING_SITE_FLAG INCOME_TAX_REPORTING_SITE ,
    HR_SHIPTO.LOCATION_CODE SHIP_TO_LOCATION ,
    HR_BILLTO.LOCATION_CODE BILL_TO_LOCATION,
    POV.CREATION_DATE CREATION_DATE,
    POV.CREATED_BY CREATED_BY,
    POV.LAST_UPDATE_DATE LAST_UPDATE_DATE,
    POV.LAST_UPDATED_BY LAST_UPDATED_BY,
    POV.LAST_UPDATE_LOGIN LAST_UPDATE_LOGIN
  FROM APPS.PO_VENDORS POV,
    APPS.PO_VENDOR_SITES_ALL POVSA ,
    APPS.FND_TERRITORIES_TL FT ,
    APPS.PO_VENDOR_CONTACTS POVC ,
    APPS.GL_CODE_COMBINATIONS GCC ,
    APPS.HR_LOCATIONS_ALL HR_SHIPTO ,
    APPS.HR_LOCATIONS_ALL HR_BILLTO ,
    APPS.PO_LOOKUP_CODES PLC
  WHERE POV.VENDOR_ID          = POVSA.VENDOR_ID
  AND FT.TERRITORY_CODE        = POVSA.COUNTRY
  AND FT.LANGUAGE              = 'US'
  AND POVC.VENDOR_SITE_ID(+)   = POVSA.VENDOR_SITE_ID
  AND GCC.CODE_COMBINATION_ID  = POVSA.ACCTS_PAY_CODE_COMBINATION_ID
  AND HR_SHIPTO.LOCATION_ID(+) = POVSA.SHIP_TO_LOCATION_ID
  AND HR_BILLTO.LOCATION_ID(+) = POVSA.BILL_TO_LOCATION_ID
  AND PLC.LOOKUP_CODE(+)       = POV.VENDOR_TYPE_LOOKUP_CODE
  AND PLC.LOOKUP_TYPE(+)       = 'VENDOR TYPE'
  AND POVSA.ORG_ID             = 2659
  AND NOT EXISTS
    (SELECT 1
    FROM APPS.AP_BANK_ACCOUNT_USES_ALL
    WHERE VENDOR_SITE_ID = POVSA.VENDOR_SITE_ID
    )
  ) )
ORDER BY VENDOR_ID;

No comments:

Post a Comment