select q.queueId, q.operatorOwnerId, q.operatorOwnerType, opr.mfrCustNum, cdr.fsl_dstId, opr.companyName from tbl_1fs_MappingQueue q with (nolock) inner join tbl_OPR_CLientOperators opr with (nolock) on opr.operatorId = q.operatorId and opr.ownerId = q.operatorOwnerId and opr.fsltablecode= q.operatorOwnerType left outer join tbl_CDR_Distributors cdr with (nolock) on cdr.ownerId = opr.ownerId and cdr.fsl_tablecode = opr.fsltablecode and cdr.cdr_recordId = opr.distrib1 where nullif( opr.fsl_choId, 0 ) is null and nullif( opr.mfrCustNUm, '' ) is not null and q.linkLevel > 0 and q.linkLevel != 99 select distinct a.ownerId as mfrId from tbl_CRM_Affiliations a with (nolock) inner join tbl_OPR_CLientOperators gpo with (nolock) on gpo.operatorId = a.orgId and gpo.ownerId = a.ownerId and gpo.fsltablecode = a.ownerType where a.ownerType = 'MFR' and a.ownerId > 0 and a.partnerAffiliateNbr = and a.orgType = 'OPR' and a.partnerType = 'OPR' and gpo.fsl_choId = and exists ( select * from tbl_OPR_CLientOperators m with (nolock) where m.ownerId = a.ownerId and m.fsltablecode = a.ownerType and m.operatorId = a.partnerId ) select distinct dd.ownerId as mfrId from tbl_OPR_DistributionDetails dd with (nolock) inner join tbl_CDR_Distributors cdr with (nolock) on cdr.cdr_recordId = dd.cdr_recordId and cdr.ownerId = dd.ownerId and cdr.fsl_tablecode = dd.ownerType where dd.ownerType = 'MFR' and dd.ownerId > 0 and dd.accountNumber = and cdr.fsl_dstId = and cdr.fsl_dstId > 0 and exists ( select * from tbl_OPR_CLientOperators m with (nolock) where m.ownerId = dd.ownerId and m.fsltablecode = dd.ownerType and m.operatorId = dd.operatorId ) select child_attrId mfrId from tbl_ORG_AttributeLinks with (nolock) where mstr_attrTypeId = 96 and child_attrTypeId = 42 and mstr_attrId = insert into tbl_ORG_AttributeLinks ( mstr_attrTypeId, mstr_attrId, child_attrTypeId, child_attrId ) values ( 96, , 42, )