SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Status Code from Db Job
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ruchirj07
Starting Member

37 Posts

Posted - 10/08/2007 :  06:09:31  Show Profile  Reply with Quote
Hi,

Below is the piece of code:

EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID,
@step_id = 1,
@step_name = N'Add Task to TCM Schedule',
@command = @strCommand,
@database_name = N'master',
@server = N'',
@database_user_name = N'',
@subsystem = N'TSQL',--run operating system command
@cmdexec_success_code = 0,
@flags = 2, --used for over writing log file
@retry_attempts = 5,
@retry_interval = 15, --retry at every 15 mins
@on_success_action = 4,
@on_success_action = 4,
@on_fail_action = 4,
@on_fail_step_id = 4

Here the @strCommand is the TSQL executing a stored procedure. Even though i'm returning status code = -1001 when stored procedure fails, the job ends successfully and deletes itself as set in the conditions while creating the job.
Is there any condition where in we can set the return code of stored procedure = return code of the job?

Or is there any other solution to this problem?

Any help will be highly appreciated.

Regards,
Ruchir

rmiao
Flowing Fount of Yak Knowledge

USA
7266 Posts

Posted - 10/08/2007 :  21:38:56  Show Profile  Reply with Quote
What do you mean return code of the job? You have to run the job to get job return code.
Go to Top of Page

ruchirj07
Starting Member

37 Posts

Posted - 10/09/2007 :  00:43:07  Show Profile  Reply with Quote
exactly.
When job runs it should return some code if it has passed, failed or hanged...
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37296 Posts

Posted - 10/09/2007 :  00:51:07  Show Profile  Visit tkizer's Homepage  Reply with Quote
This should all be handled inside the job step by T-SQL code and not by the job scheduler. Use variables and IF statements to determine the status of your stored procedure. Then decide whether or not to fail the job or let it succeed.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000