要查询数据范围的表:
Id Variance
1 2
2 17
3 7
4 4
5 20
6 1
7 111
8 8
9 18
10 67
另一张桌子
Freq StartRange EndRange
H 10 7
H 8 8
H 6 20
第一个表中的数据通过 SSIS 包每 30 分钟加载一次。
现在,我希望在方差列中的数据落在 StartRange 和 EndRange 中时触发电子邮件中的警报。
CREATE PROCEDURE [dbo].[SP_Email] @Start varchar(50),@End varchar(50),@Date datetime
AS
BEGIN
DECLARE @xml NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)
SET @xml = CAST(( SELECT [SlNo] AS 'td','',[date] AS 'td','',
[lag] AS 'td','', Percent AS 'td'
FROM TestTbl
WHERE(percent >= @Start AND percent < @End)
AND CAST(CONVERT(VARCHAR,curDate,106) AS DATETIME) = CAST(@Date AS DATETIME)
ORDER BY SlNo
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
SET @body ='<html><body><H3>Report</H3>
<table border = 1>
<tr>
<th> SlNo </th> <th> date </th> <th> lag </th> <th> Percent </th></tr>'
SET @body = @body + @xml +'</table></body></html>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Alert',
@body = @body,
@body_format ='HTML',
@recipients = 'abc@gmail.com'
@subject = 'Report';
END
请提出一个可以帮助我在 SQL Server 2005 中进行设置的过程。
提前致谢