select distinct fiscalYear, fiscalYearPeriod from tbl_IMPORT_ConAgraSales where ownerId = and ownerType = and eai_batchId = order by fiscalYear update tbl_IMPORT_ConAgraSales set fseForecast_Year = , fseForecast_Month = , fseCases = case when isNumeric( sdsSalesCases ) = 1 then convert( decimal(16,3), sdsSalesCases ) else 0 end, fseLbs = case when isNumeric( sdsSalesLbs ) = 1 then convert( decimal(16,3), sdsSalesLbs ) else 0 end, fseDollars = case when isNumeric( sdsSalesDollars ) = 1 then convert( decimal(17,2), sdsSalesDollars ) else 0 end where fiscalYear = and fiscalYearPeriod = and eai_batchId = and ownerId = and ownerType = select distinct i.salesRep from tbl_IMPORT_ConAgraSales i where i.eai_batchId = and i.ownerId = and i.ownerType = select p.territoryId, p.internalSalesId, p.name territoryName from tbl_TER_Territories t inner join tbl_TER_Territories p on p.territoryId = t.parentTerritoryId and p.ownerId = t.ownerId and p.fsl_tablecode = t.fsl_tablecode where t.ownerId = and t.fsl_tablecode = and t.internalSalesId = update tbl_IMPORT_ConAgraSales set fseSalesTerritoryId = where eai_batchId = and ownerId = and ownerType = and salesRep = update tbl_IMPORT_ConAgraSales set conagraConsolidatedTerritoryId = , conagraConsolidatedTerritoryName = where eai_batchId = and salesRep = select distinct material from tbl_IMPORT_ConAgraSales where ownerId = and ownerType = and eai_batchId = select s.sku, s.skuId, p.prodId, s.bgtCatId l1BgtCatId, p.bgtCatId l2BgtCatId 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.inactive = '0' and s.ownerId = and s.fsl_tablecode = select s.sku, s.skuId, p.prodId, s.bgtCatId l1BgtCatId, p.bgtCatId l2BgtCatId 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.inactive = '0' and s.ownerId = and s.fsl_tablecode = update tbl_IMPORT_ConAgraSales set fseSkuId = , fseSku = , fseProdId = , fseBgtCatId = where eai_batchId = and ownerId = and ownerType = and material = select distinct customer_sold_to from tbl_IMPORT_ConAgraSales where eai_batchId = and ownerId = and ownerType = 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 cdr.cdr_dstcode like order by cdr.cdr_recordId update tbl_IMPORT_ConAgraSales set fseCdr_RecordId = , fseCDRTerritoryId = , fseDistributorStatus = 'M' where eai_batchId = and ownerId = and ownerType = and customer_sold_to= select distinct fseSalesTerritoryId, customer_sold_to, customer_Sold_to_description from tbl_IMPORT_ConAgraSales where eai_batchId = and fseSalesTerritoryId is not null and fseCDR_RecordId is null insert into tbl_CDR_Distributors ( ownerId, fsl_tablecode, cdr_dstCode, cdr_dstName, cdr_territoryId, recordSource, createDate, lastUpdated ) values ( , , , ,, , , ) update tbl_IMPORT_ConAgraSales set fseCDR_RecordId = , fseCDRTerritoryId = , fseDistributorStatus = 'A' where customer_sold_to = and customer_sold_to_description = and fseSalesTerritoryId = and eai_batchId = and fseCDR_RecordId is null insert into tbl_CDR_DstCodes ( ownerId, ownerType, cdr_recordId, cdr_dstCode, cdr_dstCode_Type ) values ( , , , , 'M' ) select fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseCDRTerritoryId, sum( fseCases ) fseCases, sum( fseLbs ) fseLbs, sum( fseDollars) fseDollars from tbl_IMPORT_ConagraSales 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 group by fseforecast_year, fseforecast_month, fseSku, fseSkuId, fseProdId, fseBgtCatId, fseCdr_recordId, fseCDRTerritoryId update tbl_MFR_TPF_Detail set forecast_qty = , forecast_amt = , 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, productItemCode, prodId, bgtCategoryId, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, skuId, productLevel, mfr_id, forecast_status, territoryId ) values ( , , , , , , , , , 'CDR', , , 'SKU', , 'A', ) 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 = select fseCDRTerritoryId, fseBgtCatId, fseForecast_year, fseForecast_month, sum( fseCases ) fseCases, sum( fseDollars ) fseDollars from tbl_IMPORT_ConAgraSales where ownerId = and ownerType = and eai_batchId = and fseCDRTerritoryId is not null and fseBgtCatId is not null group by fseCDRTerritoryId, fseBgtCatId, fseForecast_year, fseForecast_month update tbl_MFR_TPF_Detail set forecast_qty = , forecast_amt = , 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 ( forecast_qty, forecast_amt, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, bgtCategoryId, productLevel, productItemCode, mfr_id, forecast_status ) values ( , , , , , , 'TER', , , 'UOM', , , 'A' ) select fseForecast_year, fseForecast_month, fseSalesTerritoryId, fseBgtCatId, sum( fseCases ) fseCases, sum( fseLbs ) fseLbs, sum( fseDollars ) fseDollars from tbl_IMPORT_ConAgraSales 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 update tbl_MFR_TPF_Detail set forecast_qty = , 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 ( forecast_qty, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, bgtCategoryId, productLevel, productItemCode, mfr_id, forecast_status ) values ( , , , , , 'TER', , , 'UOM', , , 'A' ) select fiscalYear, max( convert( int, sdsFiscalWeek )) weekNumber from tbl_IMPORT_ConAgraSales where eai_batchId = and fseBgtCatId is not null and fseSalesTerritoryId is not null group by fiscalYear order by fiscalYear desc update tbl_CRM_FiscalCalendar set weeksElapsed = where ownerId = and ownerType = and fiscalYear = and coalesce( weeksElapsed, 0 ) < select distinct fseSalesTerritoryId, fiscalYear from tbl_IMPORT_ConAgraSales where eai_batchId = and fseBgtCatId is not null and fseSalesTerritoryId is not null #_salesDataSharingHTML#