Statement in script to cause job to fail

  • I am looking for a mechanism that I can imbed in a T-SQL script that will cause a job to fail thus kicking off the 'on failure' notifications. In essence, I want to do a Select Count(*) and if the count is zero, have the job fail. Any suggestions?

  • i think any error raised with a level above 16 would fail, so in any script, you could simply add this line:

     RAISERROR ('Testing to see if a job fails for raised errors', 16, 1)

    if select count(*) from sometable

     RAISERROR ('Testing count of records was zero, aborting procedure', 16, 1)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • The RAISERROR worked really slick.  Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply