select distinct salesYear, salesMonth from tbl_IMPORT_DistributorSales where ownerId = and ownerType = and eai_batchId = order by salesYear, salesMonth update tbl_IMPORT_DistributorSales set fseForecast_Year = , fseForecast_Month = , fseFiscalYear = , fseFiscalPeriod = , fseFiscalWeek = where salesYear = and salesMonth = and eai_batchId = and ownerId = and ownerType = select distinct sku from tbl_IMPORT_DistributorSales where ownerId = and ownerType = and eai_batchId = and nullif( sku, '' ) is not null and fseSkuId is null select s.sku, s.skuId, p.prodId, s.bgtCatOverride l1BgtCatOverride, s.bgtCatId l1BgtCatId, p.bgtCatId l2BgtCatId, coalesce( s.equivUnitsPerCase, 1 ) equivUnitsPerCase from tbl_PRD_SKUS s inner join tbl_PRD_Products p on p.prodId = s.prodId and p.ownerId = s.ownerId and p.fsl_tablecode = s.fsl_tablecode where s.sku like and s.ownerId = and s.fsl_tablecode = order by s.inactive, s.skuId update tbl_IMPORT_DistributorSales set fseSkuId = , fseSku = , fseProdId = , fseBgtCatId = where eai_batchId = and ownerId = and ownerType = and sku = and fseSkuId is null select distinct customerNbr from tbl_IMPORT_DistributorSales where eai_batchId = and ownerId = and ownerType = and fseCdr_RecordId is null select cdr.cdr_recordId, ter.territoryId from tbl_CDR_Distributors cdr inner join tbl_TER_Territories ter on ter.territoryId = cdr.cdr_territoryId and ter.ownerId = cdr.ownerId and ter.fsl_tablecode = cdr.fsl_tablecode where cdr.ownerId = and cdr.fsl_tablecode = and EXISTS (SELECT * FROM tbl_CDR_Dstcodes cdrd WHERE cdrd.ownerId = cdr.ownerId AND cdrd.ownerType = cdr.fsl_tablecode AND cdrd.cdr_dstcode = AND cdrd.cdr_recordid = cdr.cdr_recordid) order by cdr.cdr_recordId update tbl_IMPORT_DistributorSales set fseCdr_RecordId = , fseSalesTerritoryId = , fseDistributorStatus = 'M' where eai_batchId = and ownerId = and ownerType = and customerNbr = and fseCdr_RecordId is null select cdrRDC.cdr_recordId from tbl_CDR_Distributors cdrRDC inner join tbl_DST_Distributors dstRDC on dstRDC.dstId = cdrRDC.fsl_dstId and dstRDC.dstCompanyType = 'RDC' where cdrRDC.ownerId = and cdrRDC.fsl_tablecode = select cdr.cdr_recordId, cdr.rdcVolumeShare, cdr.cdr_territoryId, cdr.cdr_dstCode, cdr.cdr_dstName from tbl_CDR_Distributors cdr inner join tbl_DST_Distributors dst on dst.dstId = cdr.fsl_dstId inner join tbl_CDR_Distributors cdrRDC on cdrRDC.fsl_dstId = dst.dstRDCId and cdrRDC.ownerId = cdr.ownerId and cdrRDC.fsl_tablecode = cdr.fsl_tablecode inner join tbl_TER_Territories ter on ter.territoryId = cdr.cdr_territoryId and ter.fsl_tablecode = cdr.fsl_tablecode and ter.ownerId = cdr.ownerId where cdrRDC.ownerId = and cdrRDC.fsl_tablecode = and cdrRDC.cdr_recordId = and cdr.rdcVolumeShare > 0.0 update tbl_IMPORT_DistributorSales set fseRDC = 'Y' where eai_batchId = and fsecdr_recordId in ( ) select eai_importId, fseFiscalYear, fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseSalesTerritoryId, sum( fseAlt ) fseAlt, sum( fseCases ) fseCases, sum( fseLbs ) fseLbs, sum( fseDollars) fseDollars from tbl_IMPORT_DistributorSales where eai_batchId = and fsecdr_recordId in ( ) and fseskuId is not null and fseForecast_year is not null and fseForecast_month is not null group by eai_importId, fseFiscalyear, fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseSalesTerritoryId insert into tbl_IMPORT_DistributorSales ( ownertype, ownerId, eai_batchId, eai_lineNumber, fseForecast_year, fseForecast_month, fseSKU, fseSKUId, fseProdId, fseBgtCatId, fseCdr_recordId, fseSalesTerritoryId, fseAlt, fseCases, fseLbs, fseDollars, fseFiscalYear, customerNbr, customerDesc, fseRDCId, fseDistributorStatus, fseRDCShare ) values ( , , , 0, , , , , , , , , , , , , , , , , '+', ) update tbl_IMPORT_DistributorSales set fseRDCAlt = , fseRDCCases = , fseRDCLbs = , fseRDCDollars = where eai_batchId = and ownerId = and ownerType = and eai_importId = select distinct fseforecast_year, fseforecast_month, convert( int, fseForecast_year ) sortYear, convert( int, fseForecast_month ) sortMonth from tbl_IMPORT_DistributorSales with (nolock) where eai_batchId = and ownerId = and ownerType = and fsecdr_recordId is not null and fseskuId is not null and fseForecast_year is not null and fseForecast_month is not null and fseRDC = 'N' order by sortYear, sortMonth option (recompile) delete from tbl_MFR_TPF_Detail#_tpfSuffix# where mfr_id = and forecast_status = 'A' and tPartnerType = 'CDR' and productLevel = 'SKU' and forecast_year = and forecast_month = select fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseSalesTerritoryId, sum( fseAlt ) fseAlt, sum( fseCases ) fseCases, sum( fseLbs ) fseLbs, sum( fseDollars) fseDollars from tbl_IMPORT_DistributorSales with (nolock) where eai_batchId = and fsecdr_recordId is not null and fseskuId is not null and fseForecast_year = and fseForecast_month = and fseRDC = 'N' group by fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseSalesTerritoryId option (recompile) insert into tbl_MFR_TPF_Detail#_tpfSuffix# ( forecast_qty, forecast_amt, forecast_alt, productItemCode, prodId, bgtCategoryId, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, skuId, productLevel, mfr_id, forecast_status, territoryId ) values ( , , , , , , , , , , 'CDR', , , 'SKU', , 'A', )
#_dc# = #qmd_distributorSkuSales[_dc][qmd_distributorSkuSales.currentRow]#
select distinct fseFiscalYear from tbl_IMPORT_DistributorSales with (nolock) where ownerId = and ownerType = and eai_batchId = and fseCDR_RecordId is not null and fseSKUId is not null and fseFiscalYear > 0 order by fseFiscalYear select fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseSalesTerritoryId, sum( fseAlt ) fseAlt, sum( fseCases ) fseCases, sum( fseLbs ) fseLbs, sum( fseDollars) fseDollars from tbl_IMPORT_DistributorSales where eai_batchId = and fsecdr_recordId is not null and fseskuId is not null and fseForecast_year is not null and fseForecast_month is not null and fseRDC = 'N' group by fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseSalesTerritoryId select distinct fseforecast_year, fseforecast_month from qmd_distributorSkuSales select tpf.tpartnerId, tpf.tpartnertype, tpf.forecast_status, tpf.productLevel, tpf.skuId, tpf.mfr_id, tpf.forecast_month, tpf.forecast_year, tpf.lastupdate, 'N' dropped from tbl_MFR_TPF_Detail tpf where tpf.tpartnerType = 'CDR' and tpf.forecast_status = 'A' and tpf.skuId is not null and tpf.tpartnerId is not null and tpf.mfr_id = and tpf.productLevel = 'SKU' and tpf.forecast_year = and tpf.forecast_month = delete from tbl_MFR_TPF_Detail where mfr_id = and forecast_year = and forecast_month = and tpartnerType = 'CDR' and productLevel = 'SKU' and forecast_status = 'A' and tpartnerId = and skuId = and lastUpdate = update tbl_MFR_TPF_Detail set forecast_qty = , forecast_amt = , forecast_alt = , productItemCode = , prodId = , bgtCategoryId = , lastUpdateSource = , lastUpdate = , territoryId = where forecast_year = and forecast_month = and tPartnerType = 'CDR' and tPartnerId = and productLevel = 'SKU' and skuId = and mfr_id = and forecast_status = 'A' insert into tbl_MFR_TPF_Detail ( forecast_qty, forecast_amt, forecast_alt, productItemCode, prodId, bgtCategoryId, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, skuId, productLevel, mfr_id, forecast_status, territoryId ) values ( , , , , , , , , , , 'CDR', , , 'SKU', , 'A', )
#_dc# = #qmd_distributorSkuSales[_dc][qmd_distributorSkuSales.currentRow]#
--->

Updating Territory Summaries

select fseForecast_year, fseForecast_month, fseSalesTerritoryId, fseBgtCatId, sum( fseCases ) fseCases, sum( fseLbs ) fseLbs, sum( fseDollars ) fseDollars, sum( fseAlt ) fseAlt from tbl_IMPORT_DistributorSales where eai_batchId = and ownerId = and ownerType = -- and fseBgtCatId is not null and fseSalesTerritoryId is not null group by fseForecast_year, fseForecast_month, fseSalesTerritoryId, fseBgtCatId order by fseSalesTerritoryId, fseForecast_year, fseForecast_month update tbl_MFR_TPF_Detail#_tpfSuffix# set forecast_qty = , forecast_amt = , forecast_alt = , lastUpdateSource = , lastUpdate = where forecast_year = and forecast_month = and tPartnerType = 'TER' and tPartnerId = and bgtCategoryId = and productLevel = 'UOM' and productItemCode = and mfr_id = and forecast_status = 'A' insert into tbl_MFR_TPF_Detail#_tpfSuffix# ( forecast_qty, forecast_amt, forecast_alt, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, bgtCategoryId, productLevel, productItemCode, mfr_id, forecast_status ) values ( , , , , , , , 'TER', , , 'UOM', , , 'A' ) update tbl_MFR_TPF_Detail#_tpfSuffix# set forecast_qty = , forecast_amt = , forecast_alt = , lastUpdateSource = , lastUpdate = where forecast_year = and forecast_month = and tPartnerType = 'TER' and tPartnerId = and productLevel = 'UOM' and productItemCode = 'MKT_0' and mfr_id = and forecast_status = 'A' insert into tbl_MFR_TPF_Detail#_tpfSuffix# ( forecast_qty, forecast_amt, forecast_alt, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, productLevel, productItemCode, mfr_id, forecast_status ) values ( , , , , , , , 'TER', , 'UOM', 'MKT_0', , 'A' ) select distinct fseFiscalYear fiscalYear from tbl_IMPORT_DistributorSales where eai_batchId = and fseBgtCatId is not null and fseSalesTerritoryId is not null order by fiscalYear desc select distinct fseSalesTerritoryId, fseFiscalYear fiscalYear from tbl_IMPORT_DistributorSales where eai_batchId = and fseBgtCatId is not null and fseSalesTerritoryId is not null select ter.territoryId, ter.internalSalesId, ter.name territoryName, i.fseFiscalYear fiscalYear, max( convert( int, i.fseFiscalWeek )) weekNumber from tbl_IMPORT_DistributorSales i inner join tbl_TER_Territories ter on ter.territoryId = i.fseSalesTerritoryId and ter.ownerId = i.ownerId and ter.fsl_tablecode = i.ownerType inner join tbl_TER_TerritoryLevels lvl on lvl.levelId = ter.levelId and lvl.brokerLevel = 1 where i.eai_batchId = and i.ownerId = and i.ownerType = group by ter.territoryId, ter.internalSalesId, ter.name , i.fseFiscalYear order by fiscalYear, weekNumber, territoryName select fiscalYear, max( weekNumber ) weekNumber from qmd_batchScope group by fiscalYear order by fiscalYear desc update tbl_CRM_FiscalCalendar set weeksElapsed = where ownerId = and ownerType = and fiscalYear = and coalesce( weeksElapsed, 0 ) <

Running in Partial Data Mode

Running in Full Data Mode

#_salesDataSharingHTML#