select spl.ownerId, spl.ownerType, spl.opportunityId, coalesce( spl.salesPersonUserId, coalesce( nullif( opr.mfr_bsr_id, 0 ), coalesce( spl.updateUserId, spl.createUserId ))) userId from tbl_SPL_Opportunities spl inner join tbl_SPL_Stages stg on stg.stageId = spl.stageId inner join tbl_OPR_ClientOperators opr on opr.operatorId = spl.partnerId and opr.ownerId = spl.ownerId and opr.fsltablecode = spl.ownertype and opr.crmActive = 'Y' where spl.partnerType = 'OPR' and spl.subjectType = 'PRD' and not exists( select * from tbl_OPR_ProductStatus ps where ps.ownerId = spl.ownerId and ps.ownerType = spl.ownerType and ps.prodId = spl.subjectId and ps.operatorId = spl.partnerId ) and spl.ownerType = and stg.statusCode in ( 'R', 'C', 'A', 'I' )