Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call a step within a Job

Status
Not open for further replies.

ashab02

Programmer
Jun 28, 2005
87
GB
Hello
I am writing my own Job within SQL server agent and would like to execute a certain step based on a previous statement.
So far I have
Code:
DECLARE @FLAG varchar(50)
SET @FLAG = (select status from test)
if @flag = 'Successful'
begin
'Want to call a step2 here'
end
if @flag = 'Fail'
begin
'Want to call Step3 here'
end

Basically if the status is 'Successfull I want to call an step 2 which will proceed with the rest of my job but if its fail I want it to call step 4 which will email me and notify me of an error.
Can anyone fill in the blanks for me between the Begin and End.
I'm think its something like:
Exec step1.

Can someone help?
Oh yes i'm on SQL server 2000 version 8
 
When you click on Add Step and insert your code, click on the "Advanced" tab at the top of that window, then you can tell it what to do "on success" or "on failure" of that step. You may need to put all the steps in first then work through the logical flow (obviously you cant tel step 1 to go to step 4 if you haven't entered step 4 yet!!)

HTH,

Rgds,

M.
 
Hello
Yes I'm aware of this but the problem is that i'm doing a check from something that is populated from another source so it will netiher be a failure or success. It will just be some code that needs to be executed at the start and from the result do one of two things.

What I have is a job and at the start of the job I want to run the above logic and based on whats returned I want to execute a specific step I already have.

Can someone help?
And does it make sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top