declare @tmessageid bigint
set @tmessageid = (select isnull(MAX(tmessageid), 0)
                   from tmessage)
insert into tmessage
(tmessageid, siteid, createdate, rmkenable, fmessage, ftype, fisread, freaddate, tenterprise_userid,objectname,objectid)
select @tmessageid + 1, t1.siteid, getDate(), 0, '来自【'+isnull(t1.fprovince,'')+isnull(t1.fcity,'')+'】的【'+isnull(replace(t1.fname,'?',''),'')+'】在【'+CONVERT(varchar(100), t1.createdate,120)+'】打开了您分享的《'+t2.ftitle+'》！', '素材', 0, null,t1.tenterprise_userid,'tarchives_ad',$tarchives_adid$
from tarchives_ad_shareform t1
         inner join tarchives_ad t2 on t1.siteid=t2.siteid and t1.tarchives_adid=t2.tarchives_adid
where t1.siteid=$siteid$ and  t1.tenterprise_userid=$tenterprise_userid$ and t1.tarchives_adid=$tarchives_adid$ and t1.tarchives_ad_shaid=$tarchives_ad_shaid$