Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
peterlemonjello
Yak Posting Veteran
53 Posts |
Posted - 2005-08-31 : 13:58:19
|
| I have a job with 8 steps. The first step checks for rows in a table and if none exist should fail the step so no other steps are executed. The way the developer gets the step to fail is by dividing by 0. This can't be the best way to implement this. What's the best way to explicitly fail the step? Here's the SQL used for step 1:select top 1 * from tableAif @@rowcount=0begin declare @forceerror int --Force Divide by Zero Error to stop job set @forceerror =0/0end |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-31 : 14:15:00
|
Raiserror will with specific severity levels will force a job step to fail. That is what the devide by 0 was doing. Why not this:if @@rowcount = 0 begin Raiserror('No records in tableA. Abort JobStep', 17, 1)endEDIT:Check raiserror and severity levels in books Online for detailsBe One with the OptimizerTG |
 |
|
|
peterlemonjello
Yak Posting Veteran
53 Posts |
Posted - 2005-08-31 : 14:26:54
|
| Thanks |
 |
|
|
|
|
|