SELECT X.CUSTOMER_SETID , X.CUST_ID ,X.USF_UEID ,X.USF_EFT_IND , X.DUNS_NUMBER , H.OM_COMPLETE ,X.USF_DUNS_PLUS4 FROM PS_USF_VNDR_HDR H , PS_USF_CUST_XREF X WHERE %Join(COMMON_KEYS, USF_VNDR_HDR H, USF_CUST_XREF X) AND H.USF_AGENCY_BUS_PUR IN ('1','3') AND H.OM_COMPLETE = 'N' AND X.CUST_OBJ_TYPE = 'CUST' AND X.STATUS = 'A' UNION SELECT X.CUSTOMER_SETID , X.CUST_ID ,X.USF_UEID ,X.USF_EFT_IND , X.DUNS_NUMBER , 'N' ,X.USF_DUNS_PLUS4 FROM PS_USF_CUST_XREF X , PS_USF_CUST_XREF X2 ,PS_USF_VNDR_ADDR AD WHERE X.USF_UEID = X2.USF_UEID AND X.USF_EFT_IND = X2.USF_EFT_IND AND X.CUSTOMER_SETID = X2.CUSTOMER_SETID AND X.CUST_ID = X2.CUST_ID AND X.USF_UEID= AD.USF_UEID AND X.USF_EFT_IND = AD.USF_EFT_IND AND X.CUST_OBJ_TYPE = 'CUST' AND X2.CUST_OBJ_TYPE = 'LAP' AND X.STATUS = 'A' AND AD.USF_ADDR_TYPE='AP' AND AD.USF_NAME1<>' ' AND NOT EXISTS ( SELECT 'X' FROM PS_USF_CUST_XREF X3 WHERE X3.USF_UEID = X.USF_UEID AND X3.USF_EFT_IND = X.USF_EFT_IND AND X3.CUSTOMER_SETID = X.CUSTOMER_SETID AND X3.CUST_ID = X.CUST_ID AND X3.CUST_OBJ_TYPE = 'CAP') UNION SELECT X.CUSTOMER_SETID , X.CUST_ID ,X.USF_UEID ,X.USF_EFT_IND , X.DUNS_NUMBER , 'N' ,X.USF_DUNS_PLUS4 FROM PS_USF_CUST_XREF X WHERE X.CUST_OBJ_TYPE = 'CUST' AND X.STATUS = 'A' AND NOT EXISTS ( SELECT 'X' FROM PS_USF_CUST_XREF X2 WHERE X2.USF_UEID = X.USF_UEID AND X2.USF_EFT_IND = X.USF_EFT_IND AND X2.CUSTOMER_SETID = X.CUSTOMER_SETID AND X2.CUST_ID = X.CUST_ID AND X2.CUST_OBJ_TYPE = 'UEI') UNION SELECT X.CUSTOMER_SETID , X.CUST_ID ,X.USF_UEID ,X.USF_EFT_IND , X.DUNS_NUMBER , 'N' ,X.USF_DUNS_PLUS4 FROM PS_USF_VNDR_HDR H , PS_USF_CUST_XREF X WHERE %Join(COMMON_KEYS, USF_VNDR_HDR H, USF_CUST_XREF X) AND H.USF_AGENCY_BUS_PUR IN ('1','3') AND H.OM_COMPLETE = 'Y' AND X.CUST_OBJ_TYPE = 'CUST' AND X.STATUS = 'A' AND EXISTS ( SELECT 'X' FROM PS_INSTALLATION_AR WHERE AR_IPAC = 'Y') AND EXISTS ( SELECT 'X' FROM PS_CUSTOMER C WHERE C.SETID = X.CUSTOMER_SETID AND C.CUST_ID = X.CUST_ID AND C.IPAC_INTERFACE <> 'Y' )
|