select formatId from tbl_EAI_inboundFileFormats with (nolock) where ownerId = and ownerType = and formatName = select listId from tbl_LST_PartnerLists with (nolock) where listName = 'Chain Reporting List of Accounts' and ownerId = and ownerType = select fiscalYear, lastInvoiceDate from tbl_CRM_FiscalCalendar with (nolock) where lastInvoiceDate is not null and ownerId = and ownerType = order by lastInvoiceDate desc ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) >= ) or ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) <= ) or ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) >= ) or ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) <= ) ) group by ct.contractId, opr.mfrCustNum, cdr.cdr_dstCode, s.sku, tpf.forecast_year, tpf.forecast_month order by ct.contractId, chain_code, cust_num, item, sales_month ---> select ct.contractId, 'act' as trans_type, chain.mfrCustNum as chain_code, cdr.cdr_dstCode as cust_num, s.sku as item, sum( tpf.forecast_qty ) as case_qty, sum( tpf.forecast_amt ) as dollar_value, cast( forecast_month + '/15/' + forecast_year as date ) as sales_month, cdr.cdr_dstName as cust_name, s.skuDesc as item_desc, chain.companyName as chain_name from tbl_MFR_TPF_Detail#_tpfSuffix# tpf with (nolock) inner join tbl_PRD_SKus s with (nolock) on s.skuId = tpf.skuId and s.ownerId = tpf.mfr_id and s.fsl_tablecode = inner join tbl_TPM_Requests r with (nolock) on r.requestId = tpf.rebateContractId and r.ownerId = tpf.mfr_id and r.ownerType = inner join tbl_TPM_Contracts ct with (nolock) on ct.contractId = r.contractId and ct.ownerId = r.ownerId and ct.ownertype = r.ownerType and ct.partnerType = 'OPR' inner join tbl_CRM_Affiliations a with (nolock) on a.ownerId = tpf.mfr_id and a.ownerType = '#qmd_batch.ownerType#' and a.partnerId = tpf.tPartnerId and a.partnerType = tpf.tPartnerType inner join tbl_OPR_ClientOperators chain with (nolock) on chain.operatorId = a.orgId and chain.ownerId = a.ownerId and chain.fsltablecode = a.ownerType inner join tbl_OPR_ClientOperators unit with (nolock) on unit.ownerId = tpf.mfr_id and unit.fsltablecode = '#qmd_batch.ownerType#' and unit.operatorId = tpf.tpartnerId and 'OPR' = tpf.tpartnerType and unit.independentYN = 0 and unit.oprCompanyType = '0' inner join tbl_OPR_ClientOperators chain with (nolock) on chain.ownerId = unit.ownerId and chain.fsltablecode = unit.fsltablecode and chain.operatorId = unit.oprParentCo and chain.oprCompanyType = '1' and chain.locationLevelPurchasing = 'Y' inner join tbl_OPR_ClientOperators chain with (nolock) on chain.ownerId = tpf.mfr_id and chain.fsltablecode = '#qmd_batch.ownerType#' and chain.operatorId = tpf.tPartnerId and 'OPR' = tpf.tPartnerType and ( ( chain.independentYN = 1 and chain.oprCompanyType = '0' ) or ( chain.oprCompanyType = '1' and coalesce( chain.locationLevelPurchasing, 'N' ) = 'N' )) inner join tbl_CDR_Distributors cdr with (nolock) on cdr.cdr_recordId = tpf.qualifierId and cdr.ownerId = tpf.mfr_id and cdr.fsl_tablecode = '#qmd_batch.ownerType#' and 'CDR' = tpf.qualifierType and nullif( cdr.cdr_dstCode, '' ) is not null where tpf.mfr_id = and tpf.forecast_status = 'C' and tpf.tpartnerType = 'OPR' and nullif( chain.mfrCustNum, '' ) is not null and exists ( select * from tbl_LST_PartnerListItems pli with (nolock) where pli.listId = and pli.partnerId = chain.operatorId ) and ( ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) >= ) or ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) <= ) or ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) >= ) or ( convert( int, tpf.forecast_year ) = and convert( int, tpf.forecast_month ) <= ) ) group by ct.contractId, chain.mfrCustNum, cdr.cdr_dstCode, s.sku, tpf.forecast_year, tpf.forecast_month, cdr.cdr_dstName, s.skuDesc, chain.companyName order by ct.contractId, chain_code, cust_num, item, sales_month
#_r.sql#

#_chainType#

Records: 
select #qmd_source.columnList# from qmd_source union select #qmd_source.columnList# from qmd_sourceByType order by contractId, chain_code, cust_num, item, sales_month
select trans_type, chain_code, cust_num, item, cust_name, item_desc, chain_name, sum( case_qty ) as case_qty, sum( dollar_value ) dollar_value, sales_month from qmd_source group by trans_type, chain_code, cust_num, item, sales_month, cust_name, item_desc, chain_name order by chain_code, cust_num, item, sales_month select * from qmd_actuals where trans_type = '' select #qmd_actuals.columnList# from qmd_actuals union all select #qmd_lag.columnList# from qmd_lag order by chain_code, cust_num, item, sales_month select mfrCustNum chainCode, companyName, address, city, state, zipcode, 0 exportedRows from tbl_LST_PartnerListItems pli with (nolock) inner join tbl_OPR_ClientOperators opr with (nolock) on opr.operatorId = pli.partnerId where opr.ownerId = and opr.fsltablecode = and pli.listId = order by companyName select chain_code, count(*) exportedRows from qmd_combined group by chain_code

Note: Chains with a blank chainCode will not be included in the export #_queryHTML# select ftpDirectory, ftpPassword, ftpServer, ftpUserName from tbl_EAI_InboundFTPSources where ftpDirectory = 'fse' and ownerId = and ownerType =

Development Environment: FTP Transfer Disabled

update tbl_EAI_inboundBatches set fileName = where batchId =