This SQL retrieves the full policy association list for a policy by unioning manual relationships, policy relationships, discount combinations, and experience combinations.
-- Reconstructed from ManualAffiliationSQL UNION PolicyRelationshipSQL-- UNION DiscountCombinationSQL UNION ERCombinationSQLSELECTmbr_policy_numASPolicyNumber,'M.'||pr.affil_typ_cdASRelationshipType,DECODE(parent_policy_num,mbr_policy_num,'Y','N')ASIsParentFROMpolicy_relationshipprWHERE(pr.parent_policy_num=:PolicyNumberORpr.parent_policy_num=(SELECTparent_policy_numFROMpolicy_relationshipWHEREmbr_policy_num=:PolicyNumber))UNIONSELECTDISTINCTparent_policy_numASPolicyNumber,'M.'||pr.affil_typ_cdASRelationshipType,CASEWHENparent_policy_num=(SELECTDISTINCTparent_policy_numFROMpolicy_relationshipWHEREmbr_policy_num=:PolicyNumberORparent_policy_num=:PolicyNumber)THEN'Y'ELSE'N'ENDASIsParentFROMpolicy_relationshipprWHERE(pr.parent_policy_num=:PolicyNumberORpr.parent_policy_num=(SELECTDISTINCTparent_policy_numFROMpolicy_relationshipWHEREmbr_policy_num=:PolicyNumber))UNIONSELECTpolicy_numASPolicyNumber,p.policy_relationship_code,DECODE(policy_relationship_policy_num,policy_num,'Y','N')FROMPOLICYpWHERE(p.policy_relationship_policy_num=:PolicyNumberORp.policy_relationship_policy_num=(SELECTpolicy_relationship_policy_numFROMPOLICYWHEREpolicy_num=:PolicyNumber))UNIONSELECTcpp2.policy_numASPolicyNumber,'DiscountCombination',NVL(cpp2.min_premium_member_flag,'N')FROMPOLICYp,combo_policy_periodcpp,policy_periodpp,combo_policy_periodcpp2WHEREcpp.policy_num=:PolicyNumberANDcpp.active_member_flag='Y'ANDcpp.policy_period_eff_date=pp.policy_period_eff_dateANDcpp.policy_num=pp.policy_numANDpp.policy_period_eff_date<=:cppDateANDpp.policy_period_exp_date>:cppDateANDcpp.combo_period_seq_num=cpp2.combo_period_seq_numANDcpp2.active_member_flag='Y'ANDcpp2.policy_num=p.policy_numANDcpp.active_member_flag='Y'UNIONSELECTecp2.POLICY_NUMASPolicyNumber,'ExperienceCombination',DECODE(ecp2.policy_num,p.rate_account,'Y','N')FROMpolicyp,er_combination_policyecp,er_combination_policyecp2WHEREecp.policy_num=:PolicyNumberANDecp.eff_date<=:ecDateANDNVL(ecp.exp_date,:ecDate+1)>:ecDateANDecp.policy_num=p.policy_numANDecp.er_combination_seq_num=ecp2.er_combination_seq_numANDecp2.eff_date<=:ecDateANDNVL(ecp2.exp_date,:ecDate+1)>:ecDate