SELECT SOURCE.INT_LINE_ITEM_ID, SOURCE.SOURCE_PK, E_VD.INT_VENDOR_ID, SOURCE.INT_MEMBER_ID, SOURCE.INT_PERSON_ID, SOURCE.FLT_MAXIMUM_ALLOWED, E_VD.TXT_VENDOR_NAME AS TXT_REMIT_NAME, E_VDL.TXT_ADDR1 AS TXT_REMIT_ADDR1, E_VDL.TXT_ADDR2 AS TXT_REMIT_ADDR2, E_VDL.TXT_ADDR3 AS TXT_REMIT_ADDR3, E_VDL.TXT_CITY AS TXT_REMIT_CITY, E_VDL.INT_STATE_ID AS INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, E_VDL.TXT_ZIP_5 AS TXT_REMIT_ZIP_5, E_VDL.TXT_ZIP_4 AS TXT_REMIT_ZIP_4, E_VDL.TXT_ZIP_INTL AS TXT_REMIT_ZIP_INTL, E_VDL.TXT_COUNTRY AS TXT_REMIT_COUNTRY, SOURCE.INT_VENDOR_ID AS INT_LIEN_ORIG_VENDOR_ID FROM (SELECT * FROM (( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, F_PAYMENTS.INT_VENDOR_ID, F_PAYMENTS.INT_MEMBER_ID, F_PAYMENTS.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_PAYMENTS INNER JOIN F_LINE_ITEM ON F_PAYMENTS.INT_PAYMENT_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_PAYMENTS.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_PAYMENTS.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_PAYMENTS.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_PAYMENTS.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_PAYMENTS.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE (F_PAYMENTS.INT_VENDOR_ID IS NOT NULL OR F_PAYMENTS.INT_MEMBER_ID IS NOT NULL OR F_PAYMENTS.INT_PERSON_ID IS NOT NULL) AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, F_RECOVERY.INT_VENDOR_ID, F_RECOVERY.INT_MEMBER_ID, F_RECOVERY.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_RECOVERY INNER JOIN F_LINE_ITEM ON F_RECOVERY.INT_RECOVERY_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_RECOVERY.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_RECOVERY.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_RECOVERY.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_RECOVERY.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_RECOVERY.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE (F_RECOVERY.INT_VENDOR_ID IS NOT NULL OR F_RECOVERY.INT_MEMBER_ID IS NOT NULL OR F_RECOVERY.INT_PERSON_ID IS NOT NULL) AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, F_INVOICE.INT_VENDOR_ID, NULL AS INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_INVOICE INNER JOIN F_LINE_ITEM ON F_INVOICE.INT_INVOICE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_INVOICE.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_INVOICE.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_INVOICE.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN L_STATES ON F_INVOICE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_INVOICE.INT_VENDOR_ID IS NOT NULL AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(E_VENDOR.TXT_VENDOR_NAME,'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(E_VENDOR_LOCATION.TXT_CITY,'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, NULL AS INT_VENDOR_ID, F_DEDUCTIBLE.INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_DEDUCTIBLE INNER JOIN F_LINE_ITEM ON F_DEDUCTIBLE.INT_DEDUCTIBLE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_MEMBER ON F_DEDUCTIBLE.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN L_STATES ON F_DEDUCTIBLE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_DEDUCTIBLE.INT_MEMBER_ID IS NOT NULL AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(E_MEMBER.TXT_MEMBER_NAME,'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(E_MEMBER.TXT_ADDR1,'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(E_MEMBER.TXT_ADDR2,'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(E_MEMBER.TXT_CITY,'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(E_MEMBER.INT_STATE_ID,'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_PAYMENTS.INT_PAYMENT_ID AS SOURCE_PK, F_PAYMENTS.INT_VENDOR_ID, F_PAYMENTS.INT_MEMBER_ID, F_PAYMENTS.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_PAYMENTS INNER JOIN F_LINE_ITEM ON F_PAYMENTS.INT_PAYMENT_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_PAYMENTS.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_PAYMENTS.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_PAYMENTS.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_PAYMENTS.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_PAYMENTS.INT_REMIT_STATE_ID = L_STATES.INT_STATE_ID WHERE (F_PAYMENTS.INT_VENDOR_ID IS NOT NULL OR F_PAYMENTS.INT_MEMBER_ID IS NOT NULL OR F_PAYMENTS.INT_PERSON_ID IS NOT NULL) AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'')) AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_RECOVERY.INT_RECOVERY_ID AS SOURCE_PK, F_RECOVERY.INT_VENDOR_ID, F_RECOVERY.INT_MEMBER_ID, F_RECOVERY.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_RECOVERY INNER JOIN F_LINE_ITEM ON F_RECOVERY.INT_RECOVERY_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_RECOVERY.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_RECOVERY.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_RECOVERY.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_RECOVERY.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_RECOVERY.INT_REMIT_STATE_ID = L_STATES.INT_STATE_ID WHERE (F_RECOVERY.INT_VENDOR_ID IS NOT NULL OR F_RECOVERY.INT_MEMBER_ID IS NOT NULL OR F_RECOVERY.INT_PERSON_ID IS NOT NULL) AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'')) AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_INVOICE.INT_INVOICE_ID AS SOURCE_PK, F_INVOICE.INT_VENDOR_ID, NULL AS INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_INVOICE INNER JOIN F_LINE_ITEM ON F_INVOICE.INT_INVOICE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_INVOICE.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_INVOICE.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_INVOICE.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN L_STATES ON F_INVOICE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_INVOICE.INT_VENDOR_ID IS NOT NULL AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(E_VENDOR.TXT_VENDOR_NAME,'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(E_VENDOR_LOCATION.TXT_CITY,'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,'')) AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_DEDUCTIBLE.INT_DEDUCTIBLE_ID AS SOURCE_PK, NULL AS INT_VENDOR_ID, F_DEDUCTIBLE.INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_DEDUCTIBLE INNER JOIN F_LINE_ITEM ON F_DEDUCTIBLE.INT_DEDUCTIBLE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_MEMBER ON F_DEDUCTIBLE.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN L_STATES ON F_DEDUCTIBLE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_DEDUCTIBLE.INT_MEMBER_ID IS NOT NULL AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(E_MEMBER.TXT_MEMBER_NAME,'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(E_MEMBER.TXT_ADDR1,'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(E_MEMBER.TXT_ADDR2,'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(E_MEMBER.TXT_CITY,'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(E_MEMBER.INT_STATE_ID,'')) AND INT_LOCKED_BY=1219 )) AS SOURCE ORDER BY SOURCE_PK, INT_VENDOR_ID, INT_MEMBER_ID, INT_PERSON_ID) AS SOURCE INNER JOIN E_VENDOR AS E_VS ON SOURCE.INT_VENDOR_ID=E_VS.INT_VENDOR_ID INNER JOIN E_VENDOR AS E_VD ON E_VS.INT_LIEN_VENDOR_ID=E_VD.INT_VENDOR_ID INNER JOIN E_VENDOR_LOCATION AS E_VDL ON E_VS.INT_LIEN_LOCATION_ID=E_VDL.INT_LOCATION_ID LEFT OUTER JOIN L_STATES ON E_VDL.INT_STATE_ID=L_STATES.INT_STATE_ID WHERE E_VS.BLN_LIEN=1 UNION ALL SELECT SOURCE.*, NULL AS INT_LIEN_ORIG_VENDOR_ID FROM (SELECT * FROM (( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, F_PAYMENTS.INT_VENDOR_ID, F_PAYMENTS.INT_MEMBER_ID, F_PAYMENTS.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_PAYMENTS INNER JOIN F_LINE_ITEM ON F_PAYMENTS.INT_PAYMENT_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_PAYMENTS.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_PAYMENTS.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_PAYMENTS.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_PAYMENTS.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_PAYMENTS.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE (F_PAYMENTS.INT_VENDOR_ID IS NOT NULL OR F_PAYMENTS.INT_MEMBER_ID IS NOT NULL OR F_PAYMENTS.INT_PERSON_ID IS NOT NULL) AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, F_RECOVERY.INT_VENDOR_ID, F_RECOVERY.INT_MEMBER_ID, F_RECOVERY.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_RECOVERY INNER JOIN F_LINE_ITEM ON F_RECOVERY.INT_RECOVERY_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_RECOVERY.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_RECOVERY.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_RECOVERY.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_RECOVERY.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_RECOVERY.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE (F_RECOVERY.INT_VENDOR_ID IS NOT NULL OR F_RECOVERY.INT_MEMBER_ID IS NOT NULL OR F_RECOVERY.INT_PERSON_ID IS NOT NULL) AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, F_INVOICE.INT_VENDOR_ID, NULL AS INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_INVOICE INNER JOIN F_LINE_ITEM ON F_INVOICE.INT_INVOICE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_INVOICE.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_INVOICE.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_INVOICE.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN L_STATES ON F_INVOICE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_INVOICE.INT_VENDOR_ID IS NOT NULL AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(E_VENDOR.TXT_VENDOR_NAME,'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(E_VENDOR_LOCATION.TXT_CITY,'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, -1 AS SOURCE_PK, NULL AS INT_VENDOR_ID, F_DEDUCTIBLE.INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_DEDUCTIBLE INNER JOIN F_LINE_ITEM ON F_DEDUCTIBLE.INT_DEDUCTIBLE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_MEMBER ON F_DEDUCTIBLE.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN L_STATES ON F_DEDUCTIBLE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_DEDUCTIBLE.INT_MEMBER_ID IS NOT NULL AND IFNULL(TXT_REMIT_NAME,'')=IFNULL(E_MEMBER.TXT_MEMBER_NAME,'') AND IFNULL(TXT_REMIT_ADDR1,'')=IFNULL(E_MEMBER.TXT_ADDR1,'') AND IFNULL(TXT_REMIT_ADDR2,'')=IFNULL(E_MEMBER.TXT_ADDR2,'') AND IFNULL(TXT_REMIT_CITY,'')=IFNULL(E_MEMBER.TXT_CITY,'') AND IFNULL(INT_REMIT_STATE_ID,'')=IFNULL(E_MEMBER.INT_STATE_ID,'') AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_PAYMENTS.INT_PAYMENT_ID AS SOURCE_PK, F_PAYMENTS.INT_VENDOR_ID, F_PAYMENTS.INT_MEMBER_ID, F_PAYMENTS.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_PAYMENTS INNER JOIN F_LINE_ITEM ON F_PAYMENTS.INT_PAYMENT_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_PAYMENTS.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_PAYMENTS.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_PAYMENTS.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_PAYMENTS.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_PAYMENTS.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_PAYMENTS.INT_REMIT_STATE_ID = L_STATES.INT_STATE_ID WHERE (F_PAYMENTS.INT_VENDOR_ID IS NOT NULL OR F_PAYMENTS.INT_MEMBER_ID IS NOT NULL OR F_PAYMENTS.INT_PERSON_ID IS NOT NULL) AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'')) AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_RECOVERY.INT_RECOVERY_ID AS SOURCE_PK, F_RECOVERY.INT_VENDOR_ID, F_RECOVERY.INT_MEMBER_ID, F_RECOVERY.INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_RECOVERY INNER JOIN F_LINE_ITEM ON F_RECOVERY.INT_RECOVERY_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_RECOVERY.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_RECOVERY.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN E_MEMBER ON F_RECOVERY.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN C_EVENT_PERSON ON F_RECOVERY.INT_PERSON_ID=C_EVENT_PERSON.INT_PERSON_ID AND F_RECOVERY.INT_CLAIM_ID=C_EVENT_PERSON.INT_CLAIM_ID LEFT OUTER JOIN L_STATES ON F_RECOVERY.INT_REMIT_STATE_ID = L_STATES.INT_STATE_ID WHERE (F_RECOVERY.INT_VENDOR_ID IS NOT NULL OR F_RECOVERY.INT_MEMBER_ID IS NOT NULL OR F_RECOVERY.INT_PERSON_ID IS NOT NULL) AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(IFNULL(E_VENDOR.TXT_VENDOR_NAME,IFNULL(E_MEMBER.TXT_MEMBER_NAME,CONCAT(C_EVENT_PERSON.TXT_NAME_FIRST,CONCAT(' ',C_EVENT_PERSON.TXT_NAME_LAST)))),'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,IFNULL(E_MEMBER.TXT_ADDR1,C_EVENT_PERSON.TXT_ADDR1)),'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,IFNULL(E_MEMBER.TXT_ADDR2,C_EVENT_PERSON.TXT_ADDR2)),'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.TXT_CITY,IFNULL(E_MEMBER.TXT_CITY,C_EVENT_PERSON.TXT_CITY)),'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,IFNULL(E_MEMBER.INT_STATE_ID,C_EVENT_PERSON.INT_STATE_ID)),'')) AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_INVOICE.INT_INVOICE_ID AS SOURCE_PK, F_INVOICE.INT_VENDOR_ID, NULL AS INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_INVOICE INNER JOIN F_LINE_ITEM ON F_INVOICE.INT_INVOICE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_VENDOR ON F_INVOICE.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID LEFT OUTER JOIN E_VENDOR_LOCATION ON F_INVOICE.INT_VENDOR_ID=E_VENDOR_LOCATION.INT_VENDOR_ID AND F_INVOICE.INT_LOCATION_ID=E_VENDOR_LOCATION.INT_LOCATION_ID LEFT OUTER JOIN L_STATES ON F_INVOICE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_INVOICE.INT_VENDOR_ID IS NOT NULL AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(E_VENDOR.TXT_VENDOR_NAME,'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(E_VENDOR_LOCATION.TXT_ADDR1,'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(E_VENDOR_LOCATION.TXT_ADDR2,'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(E_VENDOR_LOCATION.TXT_CITY,'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(E_VENDOR_LOCATION.INT_STATE_ID,'')) AND INT_LOCKED_BY=1219 ) UNION ( SELECT INT_LINE_ITEM_ID, F_DEDUCTIBLE.INT_DEDUCTIBLE_ID AS SOURCE_PK, NULL AS INT_VENDOR_ID, F_DEDUCTIBLE.INT_MEMBER_ID, NULL AS INT_PERSON_ID, FLT_MAXIMUM_ALLOWED, TXT_REMIT_NAME, TXT_REMIT_ADDR1, TXT_REMIT_ADDR2, TXT_REMIT_ADDR3, TXT_REMIT_CITY, INT_REMIT_STATE_ID, L_STATES.TXT_STATE_SCODE AS TXT_REMIT_STATE_SCODE, TXT_REMIT_ZIP_5, TXT_REMIT_ZIP_4, TXT_REMIT_ZIP_INTL, TXT_REMIT_COUNTRY FROM F_DEDUCTIBLE INNER JOIN F_LINE_ITEM ON F_DEDUCTIBLE.INT_DEDUCTIBLE_ID=F_LINE_ITEM.INT_PARENT_ID LEFT OUTER JOIN E_MEMBER ON F_DEDUCTIBLE.INT_MEMBER_ID=E_MEMBER.INT_MEMBER_ID LEFT OUTER JOIN L_STATES ON F_DEDUCTIBLE.INT_REMIT_STATE_ID=L_STATES.INT_STATE_ID WHERE F_DEDUCTIBLE.INT_MEMBER_ID IS NOT NULL AND (IFNULL(TXT_REMIT_NAME,'')<>IFNULL(E_MEMBER.TXT_MEMBER_NAME,'') OR IFNULL(TXT_REMIT_ADDR1,'')<>IFNULL(E_MEMBER.TXT_ADDR1,'') OR IFNULL(TXT_REMIT_ADDR2,'')<>IFNULL(E_MEMBER.TXT_ADDR2,'') OR IFNULL(TXT_REMIT_CITY,'')<>IFNULL(E_MEMBER.TXT_CITY,'') OR IFNULL(INT_REMIT_STATE_ID,'')<>IFNULL(E_MEMBER.INT_STATE_ID,'')) AND INT_LOCKED_BY=1219 )) AS SOURCE ORDER BY SOURCE_PK, INT_VENDOR_ID, INT_MEMBER_ID, INT_PERSON_ID) AS SOURCE LEFT OUTER JOIN E_VENDOR ON SOURCE.INT_VENDOR_ID=E_VENDOR.INT_VENDOR_ID WHERE E_VENDOR.BLN_LIEN=0 OR SOURCE.INT_VENDOR_ID IS NULL