select
case when int.partnertype = 'opr'
then opr.companyname
else cdr.cdr_dstname
end as companyname
from tbl_crm_interactions int
left outer join tbl_opr_clientoperators opr
on opr.operatorid = int.partnerid
and int.partnertype = 'opr'
left outer join tbl_cdr_distributors cdr
on cdr.cdr_recordid = int.partnerid
and int.partnertype <> 'opr'
where int.interactionid =
and int.ownerid =
and int.ownertype =