select
case when int.partnertype = 'opr'
then opr.companyname
else cdr.cdr_dstname
end as companyname
from tbl_crm_interactions int with (nolock)
left outer join tbl_opr_clientoperators opr with (nolock)
on opr.operatorid = int.partnerid
and int.partnertype = 'opr'
left outer join tbl_cdr_distributors cdr with (nolock)
on cdr.cdr_recordid = int.partnerid
and int.partnertype <> 'opr'
where int.interactionid =
and int.ownerid =
and int.ownertype =
select email, firstname, lastname
from tbl_crm_interactions int with (nolock)
inner join tbl_fspro_members fsp with (nolock)
on fsp.fspro_userid = int.contactid
and fsp.ownerid =
and fsp.fsl_tablecode =
where int.interactionid =
and int.ownerid =
and int.ownertype =