[英]SQL Server Agent Job custom error message
I have created a step (Transact-SQL script (T-SQL)), which contains this query: 我创建了一个步骤(Transact-SQL脚本(T-SQL)),其中包含以下查询:
SELECT
CASE WHEN SalarySum >= 10000 THEN 1
ELSE 1 / 0 END AS result
FROM dbo.salary
This query works, but I think that is bad way to stop SQL Agent Job to error message: "Divide by zero error encountered." 此查询有效,但我认为这是停止SQL Agent Job到错误消息的坏方法:“遇到零除错误”。 What is "correct" way to stop SQL Agent Job in this case, if there is an error?
如果出现错误,在这种情况下停止SQL Agent Job的“正确”方法是什么? ELSE ...
其他...
New example: 新示例:
WITH TEST_CTE
AS
(
SELECT * FROM dbo.salary
UNION ALL
SELECT * FROM dbo.salary2
)
SELECT
CASE WHEN SalarySum >= 10000 THEN 1
ELSE 1 / 0 END AS result
FROM TEST_CTE
Maybe something like.... 也许像...
IF EXISTS (SELECT 1
FROM dbo.salary
WHERE SalarySum < 10000)
BEGIN
RAISERROR('Salary Sum is less than 10000' , 16 ,1)
END
Or maybe put this into a stored procedure and call that proc from the SQL Agent job. 或者,可以将其放入存储过程中,然后从SQL Agent作业中调用该proc。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.