select * from qmd_stages where statusCode = 'A' or statusCode = 'I'
select spl.opportunityId, spl.stageId, spl.availableDate, spl.updateDate, opr.territoryId territoryId, spl.salesPersonUserId, opr.operatorId, opr.companyName, spl.subjectId, spl.subjectType,
spl.caseAmt, spl.incomeAmt, spl.weightAmt, spl.durationUnit,
p.product, p.shortDesc, stg.likelihoodPercent, spl.partnerId,
c.campaignName
from tbl_SPL_Opportunities spl
inner join tbl_PRD_Products p
on p.prodId = spl.subjectId
and p.ownerId = spl.ownerId
and p.fsl_tablecode = spl.ownerType
inner join tbl_OPR_ClientOperators opr
on opr.operatorId = spl.partnerId
inner join tbl_SPL_Stages stg
on stg.stageId = spl.stageId
left join tbl_CRM_Campaigns c
on c.campaignId = spl.campaignId
and c.ownerId = spl.ownerId
and c.ownerType = spl.ownerType
where spl.ownerId =
and spl.ownerType =
and spl.stageId in ( )
and spl.partnerType = 'OPR'
and opr.crmActive = 'Y'
and opr.dateCreated >
and (
opr.mfr_bsr_id =
or opr.territoryId in ( select territoryId from tbl_TER_Territories where primaryManager = or secondaryManager = and ownerId = )
or opr.territoryId in ( select territoryId from tbl_SMA_BrokerOfficeLink where mfr_id = and brokerId = )
or spl.salesPersonUserId =
)
order by caseAmt desc