declare @tnotice_usersid bigint
set @tnotice_usersid = (select isnull(MAX(tnotice_usersid), 0) from tnotice_users)

insert into DSBCRM..tnotice_users
(tnotice_usersid, siteid, createby, changeby, createdate, changedate, rmkenable, tnoticeid, tenterprise_userid)
select @tnotice_usersid + ROW_NUMBER() over (order by t1.siteid),
       t1.siteid, $createby$, $createby$, getdate(), getdate(), 0, $tnoticeid$,  t1.tenterprise_userid
from DSBCRM..tenterprise_users t1
inner join tnotice t2 on t1.siteid=t2.siteid and t2.tnoticeid=$tnoticeid$
where not exists(select *from tnotice_users where siteid=t1.siteid and tenterprise_userid=t1.tenterprise_userid and tnoticeid=$tnoticeid$)
and t1.siteid=$siteid$ and t1.fusertype='ÆóÒµ'and t1.fphonenumber is not null