select SSD_Cust_Num, sysco_cust_name, min( eai_lineNumber ) first_line, count(*) line_count from tbl_IMPORT_SSD_SYSCO_867 where fseCdrRecordId is null and eai_batchId = and ownerId = and ownerType = group by SSD_Cust_Num, sysco_cust_name order by line_count desc, SSD_Cust_Num, sysco_cust_name select SSD_Cust_Num, sysco_cust_name, invoice, fseClaimDate, fseClaimId, sum( claim_amt ) fseClaimAmt, case when fseClaimId is not null then case when fseClaimStatus = 'A' then 'New Claim Added' else 'Proof Of Delivery Reset' end when fseCdrRecordId is null then 'Customer Not Found' else 'Unknown mapping Issue' end import_status from tbl_IMPORT_SSD_SYSCO_867 where ownerId = and ownerType = and eai_batchId = group by SSD_Cust_Num, sysco_cust_name, invoice, fseClaimDate, fseClaimId, fseClaimStatus, fseCdrRecordId update tbl_IMPORT_SSD_SYSCO_867 set fseClaimDate = where eai_batchId = and ownerId = and ownerType = select distinct sysco_cust_name, ssd_cust_num from tbl_IMPORT_SSD_SYSCO_867 where eai_batchId = and ownerId = and ownerType = select cdr.cdr_recordId from tbl_CDR_Distributors cdr where cdr.ownerId = and cdr.fsl_tablecode = and ( cdr.cdr_dstCode = or exists ( select * from tbl_CDR_DstCodes c where c.ownerId = cdr.ownerId and c.ownerType = cdr.fsl_tablecode and c.cdr_recordId = cdr.cdr_recordId and c.cdr_dstCode = ) ) update tbl_IMPORT_SSD_SYSCO_867 set fseCdrRecordId = where eai_batchId = and ownerId = and ownerType = and sysco_cust_name = and ssd_cust_num = select fseCdrRecordId, invoice, sum( claim_amt ) from tbl_IMPORT_SSD_SYSCO_867 where ownerId = and ownerType = and eai_batchId = and fseCdrRecordId is not null and nullif( invoice, '' ) is not null group by fseCdrRecordId, invoice select claimId from tbl_TPM_Claims where ownerId = and ownerType = and payeeId = 0 and partnerType = 'CDR' and partnerId = and claimInvoice = update tbl_IMPORT_SSD_SYSCO_867 set fseClaimId = , fseClaimStatus = where ownerId = and ownerType = and eai_batchId = and fseCdrRecordId = and invoice = select fseClaimDate, fseClaimId, fseClaimStatus, fseCdrRecordId, invoice, sum( claim_amt ) claim_amt from tbl_IMPORT_SSD_SYSCO_867 where ownerId = and ownerType = and eai_batchId = and fseClaimStatus in ( 'A', 'U' ) group by fseClaimDate, fseClaimId, fseClaimStatus, fseCdrRecordId, invoice select top 1 sysco_cust_name from tbl_IMPORT_SSD_SYSCO_867 where ownerId = and ownerType = and eai_batchId = and fseCdrRecordId = insert into tbl_TPM_Claims ( createDate, createUserId, updateDate, updateUserId, ownerId, ownerType, payeeId, partnerId, partnerType, claimInvoice, claimDate, claimRef, claimType, claimStatus, statusReasonId, claimAmount, claimDescription ) values ( , -1, , -1, , , , , , , , , 'D', 'HOLD', , , ) update tbl_IMPORT_SSD_SYSCO_867 set fseClaimId = where ownerId = and ownerType = and eai_batchId = and invoice = and fseCdrRecordId = update tbl_TPM_Claims set claimDate = , claimAmount = , claimDescription = where ownerId = and ownerType = and claimId = delete from tbl_TPM_ClaimContracts where ownerId = and ownerType = and claimId = delete from tbl_TPM_ProofOfDelivery where ownerId = and ownerType = and claimId = select eai_lineNumber, fseClaimId, rtrim( left( agreement_name, 25 ) ) agreement_name, detail_customer, item, quantity, claim_amt, adj_claim_amt, contract_price, con_invoice from tbl_IMPORT_SSD_SYSCO_867 where ownerId = and ownerType = and eai_batchId = and fseClaimId > 0 order by fseClaimId, eai_lineNumber insert into tbl_IMPORT_ProofOfDelivery ( ownerId, ownertype, eai_batchId, eai_lineNumber, contract_nbr, operator_name, mfr_item_code, quantity, total_rebate_price, rebate_unit_price, contract_price, operator_inv_nbr ) values ( , , , , , , , , , , , ) select claiming_account_no, claiming_account_name, min( eai_lineNumber ) first_line, count(*) line_count from tbl_IMPORT_Deductions where fseCdrRecordId is null and eai_batchId = and ownerId = and ownerType = and not Claiming_Account_Name like '%DOT FOODS%' group by claiming_account_no, claiming_account_name order by claiming_account_no, claiming_account_name select eai_lineNumber lineNumber, claiming_account_no, claiming_account_name, check_no, created_on, requested, external_ref, case when fseClaimId is not null then case when fseClaimStatus = 'A' then 'New Claim Added' else 'Skipping Already Loaded' end when fseCdrRecordId is null then 'Customer Not Found' else 'Unknown mapping Issue' end import_status from tbl_IMPORT_Deductions where ownerId = and ownerType = and eai_batchId = order by lineNumber