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.
精彩评论