select ter.territoryId from tbl_TER_Territories ter inner join tbl_TER_TerritoryLevels lvl on lvl.levelId = ter.levelId where lvl.brokerLevel = 1 and ter.ownerId = and ter.fsl_tablecode = and ter.territoryId in ( ) select distinct parentTerritoryId as territoryId from tbl_TER_Territories ter where ter.ownerId = and ter.fsl_tablecode = and ter.territoryId in ( ) select distinct parentTerritoryId as territoryId from tbl_TER_Territories ter where ter.ownerId = and ter.fsl_tablecode = and ter.territoryId in ( ) select * from qmd_userTerritoryHierarchy2 where territoryId in ( ) order by displayOrder select fiscalYear, weeksElapsed, weeksInYear from tbl_CRM_FiscalCalendar where ownerId = and ownerType = and coalesce( weeksElapsed, 0 ) > 0 order by fiscalYear desc select fiscalYear, weeksElapsed, weeksInYear from tbl_CRM_FiscalCalendar where ownerId = and ownerType = and fiscalYear = select targetVolume as tyBudget, actualVolume as tyActual, remainingBaselineVolume as lyActual, planVolumeImpact as tyImpact, opportunityCount as planOpps, ytdRunRateVol as ytdRunRate, remainingBudgetVol as remainingBudget, remainingGrowthVol remainingGrowth, runRateNeededVol as runRateNeeded, weeklyGapVol as weeklyGap, potentialGapVol as potentialGap, targetVolumeToDate as ytdBudget , #_f#Vol as #_f# targetAlt as tyBudget, actualAlt as tyActual, remainingBaselineAlt as lyActual, planAltImpact as tyImpact, opportunityCount as planOpps, ytdRunRateAlt as ytdRunRate, remainingBudgetAlt as remainingBudget, remainingGrowthAlt remainingGrowth, runRateNeededAlt as runRateNeeded, weeklyGapAlt as weeklyGap, potentialGapAlt as potentialGap, targetAltToDate as ytdBudget , #_f#Alt as #_f# targetValue as tyBudget, actualValue as tyActual, remainingBaselineValue as lyActual, planValueImpact as tyImpact, opportunityCount as planOpps, ytdRunRateVal as ytdRunRate, remainingBudgetVal as remainingBudget, remainingGrowthVal remainingGrowth, runRateNeededVal as runRateNeeded, weeklyGapVal as weeklyGap, potentialGapVal as potentialGap, targetValueToDate as ytdBudget , #_f#Val as #_f# from qmd_hierarchyRollup where territoryId = and (( actualVolume is not null and actualVolume <> 0 ) or( targetVolume is not null and targetVolume <> 0 )) and (( actualValue is not null and actualValue <> 0 ) or( targetValue is not null and targetValue <> 0 )) select territoryId, parentTerritoryId, subjectid, subjectName, subjectType, sortRank, targetVolume as tyBudget, actualVolume as tyActual, remainingBaselineVolume as lyActual, planVolumeImpact as tyImpact, opportunityCount as planOpps , ytdRunRateVol as ytdRunRate, remainingBudgetVol as remainingBudget, runRateNeededVol as runRateNeeded, weeklyGapVol as weeklyGap, potentialGapVol as potentialGap , remainingGrowthVol remainingGrowth , targetVolumeToDate as ytdBudget , #_f#Vol as #_f# targetAlt as tyBudget, actualAlt as tyActual, remainingBaselineAlt as lyActual, planAltImpact as tyImpact, opportunityCount as planOpps , ytdRunRateAlt as ytdRunRate, remainingBudgetAlt as remainingBudget, runRateNeededAlt as runRateNeeded, weeklyGapAlt as weeklyGap, potentialGapAlt as potentialGap , remainingGrowthAlt remainingGrowth , targetAltToDate as ytdBudget , #_f#Alt as #_f# targetValue as tyBudget, actualValue as tyActual, remainingBaselineValue as lyActual, planValueImpact as tyImpact, opportunityCount as planOpps , ytdRunRateVal as ytdRunRate, remainingBudgetVal as remainingBudget, runRateNeededVal as runRateNeeded, weeklyGapVal as weeklyGap, potentialGapVal as potentialGap , remainingGrowthVal remainingGrowth , targetValueToDate ytdBudget , #_f#Val as #_f# , qmd_budgetCategories.bgtCategory from qmd_hierarchyRollup_detail, qmd_budgetCategories where qmd_hierarchyRollup_detail.territoryId = and qmd_budgetCategories.bgtCategoryId = qmd_hierarchyRollup_detail.subjectId order by sortRank, subjectName select stageId from qmd_rawStages where stageId in () statusCode in ( ) order by likelihoodPercent select t.name, t.internalSalesId, l.brokerLevel from tbl_TER_Territories t inner join tbl_TER_TerritoryLevels l on l.levelId = t.levelId where t.ownerId = and t.fsl_tablecode = and t.territoryId = select fiscalYear, weeksElapsed, weeksInYear from tbl_CRM_FiscalCalendar where ownerId = and ownerType = and fiscalYear in ( ) and ( fiscalYear >= or coalesce( weeksElapsed, 0 ) > 0 ) order by fiscalYear select spl.opportunityId, spl.stageId, stg.statusCode, spl.availableDate, spl.durationUnit, spl.quantityAmt, spl.weightAmt, spl.incomeAmt, spl.caseAmt, spl.typeCode, spl.updateDate, opr.territoryId territoryId, spl.salesPersonUserId, spl.subjectId, spl.subjectType, osd.subjectDetailId, osd.subjectDetailType , coalesce( case when s.skuId is not null then case when s.bgtCatOverride = 'Y' then s.bgtCatId else p.bgtCatId end else p.bgtCatId end, 0 ) bgtCatId, spl.mfrPlanStart planStartDate, spl.mfrPlanEnd planEndDate, spl.mfrPlanWeeks, spl.DURATIONAMT, p.mfrId, spl.partnerId, spl.partnerType, spl.cdrdistributorid, s.equivUnitsPerCase from tbl_SPL_Opportunities spl inner join tbl_OPR_ClientOperators opr on opr.operatorId = spl.partnerId left outer join tbl_SPL_OpportunitySubjectDetails osd on osd.opportunityId = spl.opportunityId and osd.subjectDetailType = 'SKU' inner join tbl_PRD_Products p on p.prodId = spl.subjectId and p.ownerId = spl.ownerId and p.fsl_tablecode = spl.ownerType left outer join tbl_PRD_Skus s on s.skuId = osd.subjectDetailId and s.ownerId = p.ownerId and s.fsl_tablecode = p.fsl_tablecode inner join tbl_SPL_Stages stg on stg.stageId = spl.stageId where spl.ownerId = and spl.ownerType = and spl.stageId in ( ) and spl.partnerType = 'OPR' and opr.crmActive = 'Y' and opr.territoryId in ( ) and spl.subjectType = 'PRD' and ( spl.availableDate between and ) select * from request.qmd_oprOpportunities where bgtCatId = select spl.opportunityId, spl.stageId, stg.statusCode, spl.availableDate, spl.durationUnit, spl.quantityAmt, spl.weightAmt, spl.incomeAmt, spl.caseAmt, spl.typeCode, spl.updateDate, cdr.cdr_territoryId territoryId, spl.salesPersonUserId, spl.subjectId, spl.subjectType, osd.subjectDetailId, osd.subjectDetailType , coalesce( case when s.skuId is not null then case when s.bgtCatOverride = 'Y' then s.bgtCatId else p.bgtCatId end else p.bgtCatId end, 0 ) bgtCatId , spl.mfrPlanStart planStartDate, spl.mfrPlanEnd planEndDate, spl.mfrPlanWeeks, spl.DURATIONAMT, p.mfrId, spl.partnerId, spl.partnerType, spl.cdrdistributorid, s.equivUnitsPerCase from tbl_SPL_Opportunities spl inner join tbl_CDR_Distributors cdr on cdr.cdr_recordId = spl.partnerId left outer join tbl_SPL_OpportunitySubjectDetails osd on osd.opportunityId = spl.opportunityId and osd.subjectDetailType = 'SKU' inner join tbl_PRD_Products p on p.prodId = spl.subjectId and p.ownerId = spl.ownerId and p.fsl_tablecode = spl.ownerType left outer join tbl_PRD_Skus s on s.skuId = osd.subjectDetailId and s.ownerId = p.ownerId and s.fsl_tablecode = p.fsl_tablecode inner join tbl_SPL_Stages stg on stg.stageId = spl.stageId where spl.ownerId = and spl.ownerType = and spl.stageId in ( ) and spl.partnerType = 'CDR' and spl.subjectType = 'PRD' and cdr.crmActive = 'Y' and cdr.cdr_territoryId in ( ) and ( spl.availableDate between and ) select * from request.qmd_cdrOpportunities where bgtCatId = select #_columnList# from qmd_oprOpportunities union select #_columnList# from qmd_cdrOpportunities union select #_columnList# from qmd_overlapOpportunities select sum( volumeImpactvalueImpact ) tyImpact, count(distinct opportunityId) opportunityCount from qmd_overlapPipeline select sum( volumeImpactvalueImpact ) tyImpact, count(distinct opportunityId) opportunityCount from qmd_oprOpportunities