update b set b.fseBudgetId = t.budgetId from tbl_IMPORT_TradeBudgets b inner join tbl_TPM_BudgetTypes t on t.ownerId = b.ownerId and t.ownerType = b.ownerType and t.budgetType = b.budget_type where b.eai_batchId = and b.ownerId = and b.ownerType = select t.name, count(*) dupCount from tbl_TER_Territories t where t.ownerId = and t.fsl_tablecode = and t.name is not null and t.name <> '' and t.name <> 'Unknown Territory' group by t.name having count(*) > 1 update b set b.fseTerritoryId = t.territoryId from tbl_IMPORT_TradeBudgets b inner join tbl_TER_Territories t on t.ownerId = b.ownerId and t.fsl_tablecode = b.ownerType and t.name = b.territory_name where b.eai_batchId = and b.ownerId = and b.ownerType = select budget_year, budget_month, fseBudgetId, fseTerritoryId, budget_dollars from tbl_IMPORT_TradeBudgets where ownerId = and ownerType = and eai_batchId = and fseTerritoryId > 0 and fseBudgetId > 0 and budget_year >= 2020 and budget_month between 01 and 12 select * from tbl_MFR_TPF_Detail#_tpfSuffix# where mfr_Id = and tPartnerType = 'TER' and tPartnerId = and qualifierType = 'TBG' and qualifierId = and forecast_status = 'B' and productLevel = 'TBG' and productItemCode = and forecast_year = and forecast_month = and forecast_amt = ---> update tbl_MFR_TPF_Detail#_tpfSuffix# set lastUpdate = , sourceOfUpdate = 'BUD' , lastUpdateSource = , forecast_amt = where mfr_Id = and tPartnerType = 'TER' and tPartnerId = and qualifierType = 'TBG' and qualifierId = and forecast_status = 'B' and productLevel = 'TBG' and productItemCode = and forecast_year = and forecast_month = insert into tbl_MFR_TPF_Detail#_tpfSuffix# (mfr_id, tpartnerId, tpartnerType, territoryId, qualifierType, qualifierId, forecast_year, forecast_month, productLevel, productItemCode, forecast_status, forecast_qty, forecast_amt, lastUpdate, sourceOfUpdate, lastUpdateSource ) values (, , , , ,, , , , , , , , , , )

Trade Budgets Processed

select territory_name, budget_type,budget_year, budget_month, sum(budget_dollars) as budget_dollars from tbl_IMPORT_TradeBudgets where ownerId = and ownerType = and eai_batchId = and fseTerritoryId > 0 and fseBudgetId > 0 and budget_year >= 2020 and budget_month between 01 and 12 group by territory_name, budget_type,budget_year, budget_month select sum(budget_dollars) as TotalBudgetLoaded from qmd_processed select sum(budget_dollars) as budgetNotLoaded from tbl_IMPORT_TradeBudgets where ownerId = and ownerType = and eai_batchId = and (nullif( fseBudgetId, 0 ) is null or nullif( fseTerritoryId, 0 ) is null or budget_year < 2020 or budget_month not between 01 and 12 ) select sum(budget_dollars) as totalBudgetOnFile from tbl_IMPORT_TradeBudgets where ownerId = and ownerType = and eai_batchId = ---> select budget_type, min( eai_lineNumber ) firstLine, count(*) as lines from tbl_IMPORT_TradeBudgets with (nolock) where eai_batchId = and ownerId = and ownerType = and nullif( fseBudgetId, 0 ) is null group by budget_type order by budget_type select territory_name, min( eai_lineNumber ) firstLine, count(*) as lines from tbl_IMPORT_TradeBudgets with (nolock) where eai_batchId = and ownerId = and ownerType = and nullif( fseTerritoryId, 0 ) is null group by territory_name order by territory_name select budget_year,budget_month, min( eai_lineNumber ) firstLine, count(*) as lines from tbl_IMPORT_TradeBudgets with (nolock) where eai_batchId = and ownerId = and ownerType = and (budget_year < 2020 or budget_month NOT BETWEEN 1 AND 12 ) group by budget_year,budget_month order by budget_year,budget_month