select distinct fc.ownerId, fc.ownerType, m.mfr_name from tbl_CRM_FiscalCalendar fc WITH (nolock) /*JF - SCRUM 29229 - 07/27/2020 - add nolocks as seen*/ inner join tblManufacturers m WITH (nolock) /*JF - SCRUM 29229 - 07/27/2020 - add nolocks as seen*/ on m.mfr_id = fc.ownerId where fc.ownerType = and fc.ownerId = and fc.ownerType = 'MFR'

#htmleditformat( mfr_name )# - Fiscal #_fiscalYear#

select territoryId, bgtCategoryId, sum( forecast_qty ) caseAmt, sum( forecast_amt ) dollarAmt, sum( forecast_alt ) altAmt from tbl_MFR_TPF_Detail#_tpfSuffix# WITH (nolock) /*JF - SCRUM 29229 - 07/27/2020 - add nolocks as seen*/ where territoryId > 0 and bgtCategoryId > 0 and tpartnerType = 'CDR' and forecast_status = 'A' and mfr_id = and forecast_month = and forecast_year = group by territoryId, bgtCategoryId order by territoryId 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 = 'A' 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', 'A', , , , , , , , , , ) select distinct tpartnerId, bgtCategoryId from tbl_MFR_TPF_Detail#_tpfSuffix# with (nolock) where mfr_Id = and tpartnerType = 'TER' and productItemCode like 'BGT%' and forecast_year = and forecast_month = and forecast_status = 'A' select territoryId, bgtCategoryId from qmd_bgtCategoryActuals where territoryId = and bgtCategoryId =
Purged #_tpfMonth#/#_tpfYear# - TerritoryID #tPartnerId#, BudgetCategoryId #bgtCategoryId#
delete from tbl_MFR_TPF_Detail#_tpfSuffix# where mfr_Id = and tpartnerType = 'TER' and productItemCode like 'BGT%' and forecast_year = and forecast_month = and forecast_status = 'A' and bgtCategoryId = and tPartnerId =
delete from tbl_TER_BusinessPlanGoals where ownerId = and ownerType = and goalType in ( 'B', 'G' ) and businessPlanId in ( select businessPlanId from tbl_TER_BusinessPlans where ownerId = and ownerType = and timeframeYear = and timeframePeriod = and businessPlanId = ) DECLARE @ownerType CHAR(3) = '#ownerType#'; DECLARE @ownerId INT = '#ownerId#'; WITH businessPlansWithMissingTerritories AS ( SELECT businessPlanId FROM tbl_TER_BusinessPlans AS tbp WITH (nolock) LEFT JOIN tbl_TER_Territories AS ter WITH (nolock) ON tbp.ownerType = ter.FSL_TableCode AND tbp.ownerId = ter.ownerId AND tbp.territoryId = ter.territoryId WHERE tbp.ownerType = @ownerType AND tbp.ownerId = @ownerId AND ter.territoryId IS NULL /*critical condition*/ ) DELETE FROM tbl_TER_BusinessPlans WHERE ownerType = @ownerType AND ownerId = @ownerId AND businessPlanId IN ( SELECT * FROM businessPlansWithMissingTerritories ) DECLARE @ownerType CHAR(3) = '#ownerType#'; DECLARE @ownerId INT = '#ownerId#'; WITH businessPlansGoalsWithMissingBusinessPlans AS ( SELECT goalId FROM tbl_TER_BusinessPlanGoals AS bpg WITH (nolock) LEFT JOIN tbl_TER_BusinessPlans AS tbp WITH (nolock) ON bpg.ownerType = tbp.ownerType AND bpg.ownerId = tbp.ownerId AND bpg.businessPlanId = tbp.businessPlanId WHERE bpg.ownerType = @ownerType AND bpg.ownerId = @ownerId AND tbp.businessPlanId IS NULL /*critical condition*/ ) DELETE FROM tbl_TER_BusinessPlanGoals WHERE goalId IN ( SELECT * FROM businessPlansGoalsWithMissingBusinessPlans ) AND ownerType = @ownerType AND ownerId = @ownerId select businessPlanId, ownerId, ownerType from tbl_TER_BusinessPlans WITH (nolock) /*JF - SCRUM 29229 - 07/27/2020 - add nolocks as seen*/ where ownerId = and ownerType = and timeframeYear = and timeframePeriod = and businessPlanId = update tbl_TER_BusinessPlans set startDate = , endDate = where businessPlanId =
#_resultsHTML#