没有存储过程返回错误

发布于 2024-10-02 19:14:15 字数 232 浏览 0 评论 0原文

我需要知道某个表中的行数。如果它低于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是我的挚爱i 2024-10-09 19:14:15

您可以使用 RAISERROR 命令。

IF (SELECT COUNT([col] FROM db.dbo.table) < 250
    RAISERROR('My error message', 15, 1)

严重性级别 15 是向作业指示命令失败的级别。

请在此处查看有关 RAISERROR 命令的更多信息。

You can use the RAISERROR command.

IF (SELECT COUNT([col] FROM db.dbo.table) < 250
    RAISERROR('My error message', 15, 1)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文