开发者

Returning Errors without a stored procedure

开发者 https://www.devze.com 2023-01-25 08:23 出处:网络
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 r

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: sel开发者_StackOverflowect case when (select cnt = count([col]) from db.dbo.table) < 250 THEN 1 ELSE 0 END


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消