0

我正在尝试发送一封通知电子邮件,她的运行总数达到或通过了设定值(如销售目标公告)..:

我有查询以获取运行总数:

DECLARE @TBL TABLE(id int, amount int);

INSERT INTO @TBL 
VALUES (1, 100), (2, 100), (3, 60), (4, 200), (5, 100);

SELECT t1.ID, t1.amount, SUM(t2.amount) as CumTotal
FROM @TBL t1
CROSS APPLY (SELECT *
             FROM @TBL
             WHERE ID <= t1.id) t2
GROUP BY t1.ID, t1.amount
HAVING SUM(t1.amount) < 300
ORDER BY t1.ID;

使用此查询设置触发器以触发 dbmail 的最有效方法是什么?

我正在使用 SQL Server 2008 R2

4

1 回答 1

0

使用作业,以特定时间间隔运行。

EXEC msdb.dbo.sp_send_dbmail @profile_name='',
@recipients='',
@subject='',
@body=@message
于 2017-03-22T11:27:36.740 回答