Thursday, October 11, 2012

Active Party Relationships SQL query


-------------------------------------------------------------------------------------------
 -- SQL statement to derive Active Party relationships related to active account parties
--------------------------------------------------------------------------------------
SELECT hr.relationship_id, hr.subject_id,
       hp.party_number subject_party_number, hr.subject_type,
       subject_table_name, object_id,
       hp.party_name Subject_Party_Name,
       (SELECT party_number
          FROM hz_parties
         WHERE party_id = hr.object_id) object_party_number, object_type,
       object_table_name, hr.party_id rel_party_id,
       (SELECT party_number
          FROM hz_parties
         WHERE party_id = hr.party_id) rel_party_number, relationship_type,
       relationship_code, directional_flag, direction_code, start_date,
       end_date
  FROM hz_relationships hr, hz_parties hp, hz_cust_accounts hca
 WHERE hp.party_id = hca.party_id
   AND hp.party_id = hr.subject_id
   AND hr.object_id<>hr.subject_id
   AND hr.status = 'A'
   AND hp.status = 'A'
   AND hr.directional_flag = 'F'
   AND TRUNC (hr.end_date) >= TRUNC (SYSDATE)
   AND hca.status = 'A';

No comments:

Post a Comment