我有这个触发器,当满足以下条件时,它应该发送一封电子邮件:
type = 234
confirmed_erp = 1
itemrequestfor = 'P'
当我排除电子邮件部分时,该过程有效,但不发送电子邮件。当我包括电子邮件部分时,它不处理任何行,也不发送电子邮件。我要去哪里错了?
为了便于阅读,我在选择和插入中省略了一些列,问题似乎出在我在之后的电子邮件部分添加内容时。
if @type ='234' AND @CONFIRMED_ERP = 1 AND @itemrequestfor = 'P'
begin
select @new_id = max(id)
from jobr_generic;
insert into 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)
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);
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.'+@NewLineChar+@NewLineChar+'Type: '+@attr4+@NewLineChar+'Desc:
'+@attr7+@NewLineChar+'Supplier: '+@attr9+@NewLineChar+'Alias:
'+@attr11+@NewLineChar+'Cost centre: '+@attr12+@NewLineChar+'Supplier
item number: '+@attr13
exec msdb.dbo.sp_send_dbmail
@profile_name = 'DoNotReplyMailProfile',
@recipients=@attr6,
@copy_recipients= 'test@test.com',
@subject = 'Item',
@body = @body2,
@body_format = 'TEXT',
@exclude_query_output = 1 ;
end
END