select distinct ter.territoryId
from tbl_TER_Territories ter with (nolock)
inner join tbl_TER_TeamMembers tt with (nolock)
on tt.territoryId = ter.territoryId
and tt.ownerId = ter.ownerId
and tt.ownertype = ter.fsl_tablecode
where ter.ownerId =
and ter.fsl_tablecode =
and tt.teamMemberUserId =
select s.sku, s.skuId, s.skuDesc, s.focusProduct
from tbl_PRD_Skus s with (nolock)
inner join tbl_PRD_Products p with (nolock)
on p.prodId = s.prodId
and p.ownerId = s.ownerId
and p.fsl_tablecode = p.fsl_tablecode
where s.ownerId =
and s.fsl_tablecode =
and case when s.bgtCatOverride = 'Y' then coalesce( s.bgtCatId, p.bgtCatId ) else p.bgtCatId end in ( )
select opr.operatorId, oprType, lastInteractionDate, cls.classificationId, opr.territoryId, opr.companyName
from tbl_OPR_ClientOperators opr with (nolock)
inner join tbl_OPR_Classifications cls with (nolock)
on cls.classificationId = opr.classificationId
and cls.ownerId = opr.ownerId
and cls.ownerType = opr.fsltablecode
where opr.ownerId =
and opr.fsltablecode =
and opr.mfr_bsr_id =
and cls.abbreviation = 'FRET'
and opr.crmActive = 'Y'
and nullif( opr.alcoholStatus, '' ) is not null
order by opr.companyName
select * from qmd_focusRetention
where territoryId in ( )
order by companyName
select * from qmd_focusRetention
where
lastInteractionDate <
--->
select distinct opr.operatorId, oprType, cls.classificationId, opr.territoryId, opr.companyName
from tbl_OPR_ClientOperators opr with (nolock)
inner join tbl_OPR_Classifications cls with (nolock)
on cls.classificationId = opr.classificationId
and cls.ownerId = opr.ownerId
and cls.ownerType = opr.fsltablecode
left outer join tbl_CRM_Interactions i with (nolock)
on i.ownerId = opr.ownerId
and i.ownerType = opr.fslTableCode
and i.dispositionUserId = opr.mfr_bsr_id
and i.partnerId = opr.operatorId
and i.partnerType = 'OPR'
where opr.ownerId =
and opr.fsltablecode =
and opr.mfr_bsr_id =
and cls.abbreviation = 'FRET'
and opr.crmActive = 'Y'
and territoryId in ( )
and
(
nullif( opr.lastInteractionDate, '' ) is null
or coalesce(opr.lastinteractionDate,'') <
)
and not
( i.interactionDate is not null
and i.interactionDate between and
and i.disposition <> '?')
order by opr.companyName
select distinct opr.operatorId, lst.listId, opr.territoryId
from tbl_OPR_ClientOperators opr with (nolock)
inner join tbl_LST_PartnerListItems ld with (nolock)
on ld.partnerId = opr.operatorId
inner join tbl_LST_PartnerLists lst with (nolock)
on lst.listId = ld.listId
and lst.partnerType = 'OPR'
and lst.ownerId = opr.ownerId
and lst.ownerType = opr.fsltablecode
and lst.listName = 'Beverage Retention'
where opr.ownerId =
and opr.fsltablecode =
and opr.mfr_bsr_id =
and opr.crmActive = 'Y'
and ( opr.lastInteractionDate is null
or opr.lastInteractionDate < )
and opr.oprType in ( '*','A','B' )
and nullif( opr.alcoholStatus, '' ) is not null
select * from qmd_beverageRetentionPastDue where territoryId in ( )
--->
select opr.operatorId, cls.classificationId, opr.territoryId
from tbl_OPR_ClientOperators opr with (nolock)
inner join tbl_OPR_Classifications cls with (nolock)
on cls.classificationId = opr.classificationId
and cls.ownerId = opr.ownerId
and cls.ownerType = opr.fsltablecode
where opr.ownerId =
and opr.fsltablecode =
and opr.mfr_bsr_id =
and cls.abbreviation = 'ACQT'
and opr.crmActive = 'Y'
and nullif( opr.alcoholStatus, '' ) is not null
select * from qmd_acquisitionTargets where territoryId in ( )
--->
select distinct partnerId from tbl_LST_PartnerListItems ld
inner join tbl_LST_PartnerLists lst with (nolock)
on lst.listId = ld.listId
and lst.partnerType = 'OPR'
and lst.ownerId =
and lst.ownerType =
and lst.listName = 'Beverage Retention'
--->
select opr.operatorId, opr.companyName, cls.abbreviation, sku.skuId
from tbl_OPR_ClientOperators opr with (nolock)
inner join tbl_SPL_Opportunities spl with (nolock)
on spl.partnerId = opr.operatorId
and spl.ownerId = opr.ownerId
and spl.ownerType = opr.fsltablecode
and spl.partnerType = 'OPR'
inner join tbl_SPL_Stages stg with (nolock)
on stg.stageId = spl.stageId
and stg.ownerId = spl.ownerId
and stg.ownerType = spl.ownerType
and stg.statusCode = 'A'
inner join tbl_OPR_Classifications cls with (nolock)
on cls.classificationId = opr.classificationId
and cls.ownerId = opr.ownerId
and cls.ownerType = opr.fsltablecode
inner join tbl_spl_opportunitySubjectDetails d with (nolock)
on d.opportunityId = spl.opportunityId
and d.ownerId = spl.ownerId
and d.ownerType = spl.ownerType
and d.subjectDetailType = 'SKU'
inner join tbl_PRD_Skus sku with (nolock)
on sku.skuId = d.subjectDetailId
and sku.ownerId = d.ownerId
and sku.fsl_tablecode = d.ownerType
inner join tbl_PRD_Products prd with (nolock)
on prd.prodId = sku.prodId
and prd.ownerId = sku.ownerId
and prd.fsl_TableCode = sku.fsl_tableCode
and prd.inactive = 0
and prd.crmActive = 'Y'
where opr.ownerId =
and opr.fsltablecode =
and spl.salesPersonUserId = -->
and opr.crmActive = 'Y'
and opr.territoryId in ()
select distinct operatorId, companyName
from qmd_beverageOpportunities
where abbreviation = 'FRET'
select * from qmd_beverageOpportunities
where operatorId in ()
--->
SELECT classificationId FROM tbl_OPR_Classifications with (nolock)
where ownerId =
and ownerType =
and abbreviation ='UNCLS'
select distinct operatorId, companyName
from qmd_beverageOpportunities
where abbreviation ='UNCLS'
select distinct opr.operatorId, opr.territoryId
from tbl_OPR_ClientOperators opr with (nolock)
inner join tbl_SPL_Opportunities spl with (nolock)
on spl.partnerId = opr.operatorId
and spl.partnerType = 'OPR'
inner join tbl_SPL_Stages stg with (nolock)
on stg.stageId = spl.stageId
and stg.ownerId = spl.ownerId
and stg.ownerType = spl.ownerType
where opr.ownerId =
and opr.fsltablecode =
and opr.crmActive = 'Y'
and stg.statusCode = 'A'
and spl.salesPersonUserId =
-- and spl.caseAmt >= 104
and nullif( opr.alcoholStatus, '' ) is not null
select * from qmd_operatorOpportunities where territoryId in ( )
select * from qmd_operatorOpportunities where operatorId in ( )
select * from qmd_operatorOpportunities where operatorId not in ( )
select cdr.cdr_recordId, cdr.cdr_territoryId as territoryId
from tbl_CDR_Distributors cdr with (nolock)
where cdr.ownerId =
and cdr.fsl_tablecode =
and cdr.mfr_bsr_id =
and cdr.crmActive = 'Y'
select * from qmd_distributors where territoryId in ( )
select distinct cdr.cdr_recordId, cdr.cdr_territoryId as territoryId
from tbl_CDR_Distributors cdr with (nolock)
inner join tbl_SPL_Opportunities spl with (nolock)
on spl.partnerId = cdr.cdr_recordId
and spl.partnerType = 'CDR'
and spl.ownerId = cdr.ownerId
and spl.ownertype = cdr.fsl_tablecode
inner join tbl_SPL_Stages stg with (nolock)
on stg.stageId = spl.stageId
and stg.ownerId = spl.ownerId
and stg.ownerType = spl.ownerType
where cdr.ownerId =
and cdr.fsl_tablecode =
and cdr.crmActive = 'Y'
and stg.statusCode = 'A'
and spl.salesPersonUserId =
-- and spl.caseAmt >= 104
select * from qmd_distributorOpportunities where territoryId in ( )
--->
select stageId
from tbL_SPL_Stages with (nolock)
where ownerId =
and ownerType =
and statusCode = 'A'
SELECT prodLine_ID AS lineId
FROM tbl_MFR_ProductLines
where mfr_id =
and productLine ='Beverage'