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.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 setup sql job

Author  Topic 

heliang
Starting Member

38 Posts

Posted - 2013-08-05 : 15:56:43
I need to setup something in SQL job, which will call a procedure (sp_checkrows). If it returns anything then go to next step. otherwise quick and sent error message. How could I do that?

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-08-05 : 16:11:43
Step1 - execute stored procedure and check for @@ROWCOUNT > 0. RAISERROR if zero and use "quit the job reporting failure" for "on failure action" to fail the job and exit; if greater than zero, use "go to the next step" for "on success action".
Step2 - next step.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

heliang
Starting Member

38 Posts

Posted - 2013-08-06 : 14:40:08
I have following, but do not know how to go further. What does that look like? and how it work with success and fail actions?
begin
exec dbo.sp_checkrows
if @@ROWCOUNT<>0
Print 'Successes: '
else
RAISERROR ('fail',16,1)
end
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-08-06 : 15:02:34
Use 19 instead of 16 for RAISERROR. Using 19 will cause the job to fail. You then would setup the proper actions in the job step (Advanced page).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -