select t1.tagentsid,t3.fname fsaler,t2.fagentnum,t2.fagentname,t2.fprovince,t2.fcity,t2.fcounty,count(t1.tagentsid)fcount from DSBCRM..tcustomer_reception t1
inner join DSBCRM..tagents t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid
left join DSBCRM..tenterprise_users t3 on t2.siteid=t3.siteid and t2.fsaleruserid=t3.tenterprise_userid
where t1.ftype='ÏúÊÛ' and t1.siteid=$siteid$ and
convert(varchar(7),t1.fdate,120)>=$fbegmonth$ and convert(varchar(7),t1.fdate,120)<=$fendmonth$
group by t1.tagentsid,t2.fagentnum,t2.fagentname,t2.fprovince,t2.fcity,t2.fcounty,t3.fname




