select cdr_recordId partnerId, 'CDR' partnerType, cdr_dstName partnerName, fsl_dstId from tbl_CDR_Distributors where fsl_dstId = #_usfoodsFSLId# and ownerId = and fsl_tablecode = select distinct location, location_number from tbl_IMPORT_USfoodsDeductions where eai_batchId = and ownerId= and ownerType = and type in ( ) select top 1 cdr.cdr_recordId, cdr.fsl_mapPriority from tbl_CDR_Distributors cdr inner join tbl_DST_Distributors dst on dst.dstId = cdr.fsl_dstId and dst.dstParentCo = where cdr.ownerId = and cdr.fsl_tablecode = and dst.dstBranchId = order by cdr.fsl_mapPriority select cdr.cdr_recordId, cdr.fsl_mapPriority from tbl_CDR_Distributors cdr inner join tbl_DST_Distributors dst on dst.dstId = cdr.fsl_dstId and dst.dstParentCo = where cdr.ownerId = and cdr.fsl_tablecode = and dst.dstOtherId = order by cdr.fsl_mapPriority update tbl_IMPORT_USfoodsDeductions set fseCdrRecordId = where ownerId = and ownerType = and eai_batchId = and location = and fseCdrRecordId is null and type in ( ) update tbl_IMPORT_USfoodsDeductions set fseCdrRecordId = where ownerId = and ownerType = and eai_batchId = and location = and fseCdrRecordId is null and type in ( ) select eai_importId, eai_lineNumber, fseCdrRecordId, program, description, invoice, invoice_date, type, amount from tbl_IMPORT_USfoodsDeductions where ownerId = and ownerType = and eai_batchId = and fseCdrRecordId is not null select claimId, partnerId, partnerType from tbl_TPM_Claims where ownerId = and ownerType = and claimInvoice = and claimDate = and claimAmount = and partnerId = and partnerType = 'CDR' update tbl_IMPORT_USfoodsDeductions set fseClaimId = , fseClaimStatus = where ownerId = and ownerType = and eai_batchId = and eai_importId = and eai_lineNumber = update tbl_IMPORT_USfoodsDeductions set fseClaimStatus = 'S' where ownerId = and ownerType = and eai_batchId = and type not in ( ) select eai_lineNumber, eai_importId, fseCdrRecordId, invoice, invoice_date, amount, type, description, program, amount from tbl_IMPORT_USfoodsDeductions where ownerId = and ownerType = and eai_batchId = and fseClaimStatus = 'A' select claimId from tbl_TPM_Claims where ownerId = and ownerType = and partnerType = 'CDR' and partnerId = and claimInvoice = and claimDate = and claimAmount = update tbl_IMPORT_USfoodsDeductions set fseClaimStatus = 'R' where ownerId = and ownerType = and eai_batchId = and eai_importId = and eai_lineNumber = insert into tbl_TPM_Claims ( createDate, createUserId, updateDate, updateUserId, ownerId, ownerType, partnerId, partnerType, claimInvoice, claimDate, claimRef, claimType, claimStatus, statusReasonId, claimAmount, claimDescription ) values ( , -1, , -1, , , , , , , , 'D', 'HOLD', , , ) update tbl_IMPORT_USfoodsDeductions set fseClaimId = where ownerId = and ownerType = and eai_batchId = and eai_importId = and eai_lineNumber = select location_number, location, min( eai_lineNumber ) firstLine, sum( amount ) claimTotal from tbl_IMPORT_USfoodsDeductions where ownerId = and ownerType = and eai_batchId = and fseCdrRecordId is null and type in ( ) group by location_number, location order by claimTotal desc select eai_lineNumber lineNumber, location_number, location, program, description, invoice, invoice_date, amount, type, case when fseClaimStatus = 'S' then 'S - Ignoring ' + type when nullif( fseClaimId, 0 ) is not null then case when fseClaimStatus = 'A' then 'A - New Claim Added' else 'U - Skipping Already Loaded' end when fseCdrRecordId is null then 'X - Customer Not Found' when fseClaimStatus = 'R' then 'R - Duplicate Claim' else 'M - Possible Duplicate Claim and/or Customer Mapping Changed' end import_status from tbl_IMPORT_USfoodsDeductions where ownerId = and ownerType = and eai_batchId = order by import_status, lineNumber