我正在尝试创建一个触发器,一旦将记录添加到所述表中就应该发送邮件。为此我创建了一个以下触发器,它符合我的要求:
ALTER TRIGGER [dbo].[EMAIL_ALERT_NEW]
ON [dbo].[APTCR_LOG]
after insert
as
BEGIN
SET NOCOUNT ON;
DECLARE @body NVARCHAR(MAX) = N'';
SELECT AUDTUSER, NAMERMIT ,AMTRMITTC,IDRMIT FROM APTCR_LOG inserted
SELECT @body += CHAR(13) +++ CHAR(10) +++ RTRIM(AUDTUSER) +++ RTRIM(NAMERMIT) +++RTRIM(AMTRMITTC) +RTRIM(IDRMIT) FROM APTCR_LOG inserted;
--SELECT NAMERMIT, AUDTUSER ,AMTRMITTC FROM APTCR_LOG WHERE AMTRMITTC > 100000
BEGIN
--SELECT AUDTUSER, NAMERMIT ,AMTRMITTC,IDRMIT FROM APTCR_LOG inserted WHERE AMTRMITTC > 100000.000
EXEC msdb.dbo.sp_send_dbmail
@recipients = 'ublaze@gmail.com',
@profile_name = 'default',
@subject = 'NEW PAYMENT',
@body = @body;
END
end
问题是它在桌子上发送了所有记录,我只需要添加到表格中的最后一条记录。
有人可以帮忙解决这个问题吗?