select *
from (
       select ROW_NUMBER() over (order by t1.fscore desc) queryrow,
              t2.fcontact as                              fname,
              t2.fprovince,
              t2.fcity,
              t2.fcounty,
              t1.fscore,
              t1.tagentsid
       from DSBCRM..tactionscore t1
              inner join DSBCRM..tagents t2 on t1.siteid = t2.siteid and t1.tagentsid = t2.tagentsid
       where t1.siteid=$siteid$
     ) t
where t.tagentsid=$tagentsid$




