sql server 2008 - Setup SQL Trigger to email based on multiple values from one column -
i'm trying setup trigger email me if column (stradmitreason
) matches set number of values. there added problem of column populated based on free text field, why of values surrounded %%. can't change that.
ideally really, email if second column value a01. why have second if begin i'm not sure if going wrong or if else. or if totally screwed up.
the patientlist
table populated automatically hl7 data stream. information populating properly.
any advice appreciated!!
i have changed things bit there table called admit_coremeasures after trigger executed, account number gets put new table. next time trigger runs first checks admit_coremeasures before going further. primary tablet 'patientlist' gets thousand lines written in day, conditions trigger met 2-3 dozen times day
i understand saying issues dbmail, way know send email have gotten work
where have right now:
alter trigger [dbo].[trgadmit] on [dbo].[tbl_patientlist] after insert, update begin -- set nocount on added prevent result sets -- interfering select statements. set nocount on; declare @strcpsiacct varchar(16), @stradmitreason varchar(40), @strlastevncode varchar(3) select @strcpsiacct = d.strcpsi_acct, @stradmitreason = d.stradmitreason, @strlastevncode = d.strlastevncode inserted d declare @existcount int set @existcount = (select count(*) admit_coremeasures strcpsi_acct = @strcpsiacct) if (@existcount = 0) begin if (@stradmitreason '%pne%' or @stradmitreason '%chf%' or @stradmitreason '%chest%' or @stradmitreason '%myo%' or @stradmitreason '%heart%' or @stradmitreason '%cp%' or @stradmitreason '%tia%' or @stradmitreason '%stroke%' or @stradmitreason '%cva%') begin if (@strlastevncode = 'a01') begin insert admit_coremeasures (strcpsi_acct) values (@strcpsiacct) declare @v_email_msg varchar(96) set @v_email_msg = 'potential core measure admission: account #' + (@strcpsiacct) + ' ' + (@stradmitreason) exec msdb.dbo.sp_send_dbmail @recipients = 'myemail@company.org;', @body = @v_email_msg, @subject = @v_email_msg, @profile_name ='basic-email'; end end end
Comments
Post a Comment