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+1,$siteid$, $createby$, $createby$, getdate(), getdate(), 0, $tnoticeid$, $tenterprise_userid$
where not exists(select *from tnotice_users where siteid=$siteid$ and tenterprise_userid=$tenterprise_userid$ and tnoticeid=$tnoticeid$)



