select distinct item_nbr from tbl_IMPORT_Smuckers_CustomerBudgets where eai_batchId = and fseSKUId is null select s.skuId, s.equivUnitsPerCase, case when s.bgtCatOverride = 'Y' then s.bgtCatId else coalesce( p.bgtCatId, 0 ) end bgtCatId, coalesce( p.prodId, 0 ) prodId, s.unitPrice from tbl_PRD_Skus s left outer join tbl_PRD_Products p on p.prodId = s.prodId and p.ownerId = s.ownerId and p.fsl_tablecode = s.fsl_tablecode where s.ownerId = and s.fsl_tablecode = and s.sku = and s.inactive = '0' update tbl_IMPORT_Smuckers_CustomerBudgets set fseSKUId = , fseBgtCatId = , fseProdId = , fseUnitPrice = , fseEUFactor = where ownerId = and ownerType = and eai_batchId = and item_nbr = select distinct cust_id from tbl_IMPORT_Smuckers_CustomerBudgets where ownerId = and ownerType = and eai_batchId = and fseCdr_RecordId is null select cdr.cdr_recordId, cdr.cdr_territoryId from tbl_CDR_DstCodes cn inner join tbl_CDR_Distributors cdr on cdr.cdr_recordId = cn.cdr_recordId and cdr.ownerId = cn.ownerId and cdr.fsl_tablecode = cn.ownerType where cn.ownerId = and cn.ownerType = and cn.cdr_dstcode = order by cdr.cdr_recordId update tbl_IMPORT_Smuckers_CustomerBudgets set fseCDR_RecordId = , fseTerritoryId = where ownerId = and ownerType = and eai_batchId = and cust_id = select plan_period, fseTerritoryId, fseBgtCatId, sum( plan_eus / fseEUFactor ) caseAmt, sum( plan_eus ) altAmt, avg( fseUnitPrice ) avgCasePrice from tbl_IMPORT_Smuckers_CustomerBudgets i where eai_batchId = and fseBgtCatId > 0 and fseTerritoryId in ( select ter.territoryId from tbl_TER_Territories ter inner join tbl_TER_TerritoryLevels lvl on lvl.levelId = ter.levelId where ter.ownerId = and ter.fsl_tablecode = and lvl.brokerLevel = 1 and lvl.businessPlanReviewCycle = 'Y' ) group by plan_period, fseTerritoryId, fseBgtCatId order by plan_period, fseTerritoryId update tbl_MFR_TPF_Detail#_tpfSuffix# set forecast_qty = , forecast_amt = , forecast_alt = , lastUpdateSource = , lastUpdate = where mfr_id = and tpartnerType = 'TER' and tpartnerId = and bgtCategoryId = and productItemCode = and productLevel = 'UOM' and forecast_status = 'Q' and forecast_year = and forecast_month = insert into tbl_MFR_TPF_Detail#_tpfSuffix# ( mfr_id, tpartnerType, tpartnerId, productLevel, forecast_status, forecast_year, forecast_month, forecast_qty, forecast_amt, forecast_alt, bgtCategoryId, lastUpdateSource, lastUpdate, productItemCode, territoryId ) values ( , 'TER', , 'UOM', 'Q', , , , , , , , , , ) update tbl_IMPORT_Smuckers_CustomerBudgets set fseProcessed = 'Y' where eai_batchId = and fseTerritoryId = and plan_period = and fseBgtCatId = update tbl_MFR_TPF_Detail#_tpfSuffix# set forecast_qty = , forecast_amt = , forecast_alt = , lastUpdateSource = , lastUpdate = where mfr_id = and tpartnerType = 'TER' and tpartnerId = and productItemCode = and productLevel = 'UOM' and forecast_status = 'Q' and forecast_year = and forecast_month = insert into tbl_MFR_TPF_Detail#_tpfSuffix# ( mfr_id, tpartnerType, tpartnerId, productLevel, forecast_status, forecast_year, forecast_month, forecast_qty, forecast_amt, lastUpdateSource, lastUpdate, productItemCode, territoryId ) values ( , 'TER', , 'UOM', 'Q', , , , , , , , ) select distinct fseTerritoryId from qmd_budgets