Sunday 12 April 2015

Query to findout CustomerNumber and SiteNumber from Order

SELECT
         bill_cust_acct.account_number "Billto Customer Number"           ,
         ship_cust_acct.account_number "Shipto Customer Number"           ,
         bill_party_site.party_site_number "BillTo Site Number" ,
         ship_party_site.party_site_number "ShipTo Site Number"
  FROM   oe_order_headers_all ooha,
         hz_cust_site_uses_all bill_csu,
         hz_party_sites bill_party_site,
         hz_loc_assignments bill_loc_assign,
         hz_locations bill_loc,
         hz_cust_acct_sites_all bill_acct_site,
         hz_parties bill_party,
         hz_cust_accounts bill_cust_acct,
         hz_cust_site_uses_all ship_csu,
         hz_party_sites ship_party_site,
         hz_loc_assignments ship_loc_assign,
         hz_locations ship_loc,
         hz_cust_acct_sites_all ship_acct_site,
         hz_parties ship_party,
         hz_cust_accounts ship_cust_acct
 WHERE       ooha.invoice_to_org_id = bill_csu.site_use_id(+)
         AND bill_csu.cust_acct_site_id = bill_acct_site.cust_acct_site_id(+)
         AND bill_acct_site.party_site_id = bill_party_site.party_site_id(+)
         AND bill_acct_site.cust_account_id =
               bill_cust_acct.cust_account_id(+)
         AND bill_loc.location_id(+) = bill_party_site.location_id
         AND bill_loc.location_id = bill_loc_assign.location_id(+)
         AND NVL (bill_acct_site.org_id, -99) =
               NVL (bill_loc_assign.org_id, -99)
         AND bill_cust_acct.party_id = bill_party.party_id
         AND ooha.ship_to_org_id = ship_csu.site_use_id(+)
         AND ship_csu.cust_acct_site_id = ship_acct_site.cust_acct_site_id(+)
         AND ship_acct_site.party_site_id = ship_party_site.party_site_id(+)
         AND ship_acct_site.cust_account_id =
               ship_cust_acct.cust_account_id(+)
         AND ship_loc.location_id(+) = ship_party_site.location_id
         AND ship_loc.location_id = ship_loc_assign.location_id(+)
         AND NVL (ship_acct_site.org_id, -99) =
               NVL (ship_loc_assign.org_id, -99)
         AND ship_cust_acct.party_id = ship_party.party_id
         AND ooha.order_number = 10063583

No comments:

Post a Comment