select t1.createby,
       t1.changeby,
       t1.createdate,
       t1.changedate,
       t1.tnoticeid,
       t1.tenterprise_userid,
       t1.tnotice_usersid,
       t2.fname,
       t2.fphonenumber,
       t2.frole,
       t2.fusertype,
       t2.fisadministrator,
       t3.fagentname,
       t3.ftype as fagenttype
from DSBCRM..tnotice_users t1
         inner join DSBCRM..tenterprise_users t2
                    on t1.siteid = t2.siteid and t1.tenterprise_userid = t2.tenterprise_userid
         left join DSBCRM..tagents t3 on t2.siteid = t3.siteid and t2.tagentsid = t3.tagentsid
where t1.siteid =$siteid$ and t1.tnoticeid=$tnoticeid$ and $where$