select t1.tgroupusersid,
       t1.tusergroupid,
       t1.tenterprise_userid,
       t2.fname,
       t2.fsex,
       t2.frole,
       t2.fphonenumber,
       t2.fisadministrator,
       t2.fusertype,
       t3.fagentname ,
       t3.fprovince,
       t3.fcity,
       t3.fcounty
from DSBCRM..tgroupusers 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 tusergroupid=$tusergroupid$ and $where$
