我有一个自定义数据库sql触发器,如果满足先前条件,它将插入新行。
问题是,如果我在下面注释掉的代码中包含电子邮件部分,则数据库上的Confirmed_Erp标志不会起作用。
我是否需要添加延迟或如何重写此延迟,以确保将Confirmed_Erp标志设置为1,因此将发送电子邮件。电子邮件条件之一是Confirmed_erp = 1
有一个应用程序正在数据库之上运行,该应用程序运行作业,并且一旦作业完成,数据库中的Confirmed_erp标志将变为1。
代码:
begin
select @new_id = max(id) from jobr_generic;
insert jobr_generic (id, type, jobr_ts, customerno, str_attr1,str_attr3,
dec_attr1, str_attr4,str_attr5, str_attr6,
str_attr7,str_attr8,str_attr9,str_attr10,str_attr11,str_attr12,str_attr13,str_attr14,str_attr15,str_attr16,str_attr17,str_attr18,str_attr19,str_attr20, send_erp,species, maincut, subcut, meatgroup, packtype, factorycode, supplyingsite, currency)
values (@new_id+1, '235', getdate(), @customerno,@attr1, @attr3, @decattr1, @attr4, @attr5, @attr6, @attr7, @attr8, @attr9, @attr10, @attr11, @attr12, @attr13, @attr14, @attr15, @attr16, @attr17, @attr18, @attr19, @attr20, 1, @species,@maincut,@subcut,@meatgroup,@packtype,@factorycode,@supplyingsite,@currency);
end
if @type ='235' AND @CONFIRMED_ERP = 1 AND @itemrequestfor = 'P'
begin
declare @body2 varchar(1024)
set @body2 = 'Primal Item: '+@attr16+ ' has been created and is ready
for use.'
exec msdb.dbo.sp_send_dbmail
@profile_name = 'DoNotReplyMailProfile',
@recipients= 'test@test.com',
@copy_recipients= 'test1@test.com',
@subject = 'A Primal Item has been Created',
@body = @body2,
@body_format = 'TEXT',
@exclude_query_output = 1 ;
end