没有存储过程返回错误
我需要知道某个表中的行数。如果它低于 250 行,我需要向 sql 作业返回一个错误,强制它退出。问题是它不是存储过程。它的 SQL 代码作为 Transact-SQL 脚本直接从作业步骤运行。这是否可以返回任何东西,或者是否有更好的方法来做到这一点?
这就是我所拥有的: 选择 case when (select cnt = count([col]) from db.dbo.table) < 250 那么 1 其他 0 结束
I need to know the number of rows in a certain table. If it is under 250 rows I need to return an error to the sql job forcing it to quit. The problem is it's not a stored procedure. It's sql code is running straight from the job step as a Transact-SQL script. Is this possible to return anything, or is there a better way to do this?
This is what I have:
select case when (select cnt = count([col]) from db.dbo.table) < 250 THEN 1 ELSE 0 END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 RAISERROR 命令。
严重性级别 15 是向作业指示命令失败的级别。
请在此处查看有关 RAISERROR 命令的更多信息。
You can use the RAISERROR command.
The severity level 15 is a level that will indicate to the job that the command failed.
Look here for more about the RAISERROR command.