Monday, 30 January 2012

BANK TO SUPPLIER QUERY

SELECT cust.party_name                   customer_name
02    ,      cust_acct.account_number
03    ,      cust_uses.site_use_code
04    ,      cust_loc.address1
05    ,      cust_loc.address2
06    ,      cust_loc.address3
07    ,      cust_loc.address4
08    ,      cust_loc.city
09    ,      cust_loc.postal_code
10    ,      bank.party_name                   bank_name
11    ,      bank_prof.home_country
12    ,      branch.party_name                 branch_name
13    ,      branch_prof.bank_or_branch_number branch_number
14    ,      account.bank_account_num
15    ,      account.bank_account_name
16    FROM   hz_parties bank
17    ,      hz_relationships rel
18    ,      hz_parties branch
19    ,      hz_organization_profiles bank_prof
20    ,      hz_organization_profiles branch_prof
21    ,      iby_ext_bank_accounts account
22    ,      iby_account_owners acc_owner
23    ,      iby_external_payers_all ext_payer
24    ,      iby_pmt_instr_uses_all acc_instr
25    ,      hz_parties cust
26    ,      hz_cust_accounts cust_acct
27    ,      hz_cust_acct_sites_all cust_site
28    ,      hz_cust_site_uses_all cust_uses
29    ,      hz_locations cust_loc
30    WHERE  1=1
31    AND    bank.party_id = rel.object_id
32    and    bank.party_type = rel.object_type
33    AND    rel.object_table_name = 'HZ_PARTIES'
34    AND    rel.relationship_code = 'BRANCH_OF'
35    AND    rel.subject_id = branch.party_id
36    AND    rel.subject_type = branch.party_type
37    AND    rel.subject_table_name = 'HZ_PARTIES'
38    AND    bank.party_id = bank_prof.party_id
39    AND    branch.party_id = branch_prof.party_id
40    AND    bank.party_id = account.bank_id
41    AND    branch.party_id = account.branch_id
42    AND    account.ext_bank_account_id = acc_owner.ext_bank_account_id
43    AND    acc_owner.account_owner_party_id = cust.party_id
44    AND    account.ext_bank_account_id = acc_instr.instrument_id
45    AND    acc_instr.ext_pmt_party_id = ext_payer.ext_payer_id
46    AND    ext_payer.cust_account_id = cust_acct.cust_account_id
47    AND    cust_acct.cust_account_id = cust_site.cust_account_id
48    AND    cust_site.cust_acct_site_id = cust_uses.cust_acct_site_id
49    AND    cust_uses.site_use_id = ext_payer.acct_site_use_id
50    AND    cust_uses.location = cust_loc.location_id
51    AND    cust.party_id = cust_acct.party_id;

No comments:

Post a Comment