Wednesday, May 16, 2012

Query to find the Primary Customer Information based on the org_id



    SELECT *
    FROM   hz_parties hp,
                   hz_cust_accounts hca,
                   hz_party_sites hps1,
                   hz_locations hl1,
                   hz_cust_acct_sites_all hcas1,
                   hz_cust_site_uses_all hcsu1
    WHERE   hp.party_id                = hca.party_id
    AND hp.party_id                      = hps1.party_id
    AND hp.party_id                      = hps1.party_id
    AND hl1.location_id                  = hps1.location_id
    AND hps1.party_site_id          = hcas1.party_site_id
    AND hcas1.cust_account_id    = hca.cust_account_id
    AND hcas1.cust_acct_site_id  = hcsu1.cust_acct_site_id
    AND hcsu1.site_use_code        IN ('BILL_TO','SHIP_TO')
    AND hcsu1.primary_flag         = 'Y'
    AND hcsu1.status                      = 'A'
    AND hca.cust_account_id        = <sold_to_org_id>;

No comments:

Post a Comment