Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

running sql agent job step based on value returned by a query

Posted on 2015-01-07
5
Medium Priority
?
178 Views
Last Modified: 2015-01-21
I am creating a sql agent job in MS SQL server 2008 R2.
First step runs a query to get validation status from the database. I want to run the second step only if validation_status = 1, or quit the job returning failure if validation_status <>1
One way of accomplishing this is to create a new job with the second step and use an if statement in step1 to run the second job.
Is there a better way where I can I accomplish this in the same job, to run the second step based on the outcome of query on first step?

Thank you for your help.
0
Comment
Question by:patd1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 40535919
You can set the value of  "Process Exit code of a successful command " for the fist step, by default it is zero.
You may need to alter the step to return a different value in case it is not successful using a return statement.
0
 

Author Comment

by:patd1
ID: 40537940
Aneesh, thanks for answering. Can you please give me an example for how to set Process Exit Code. Google didnt help much.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 40538030
Goto job properties -> double click on step1 of the your job, just under the "Run As " selection box, you can see Process Exit Code text box
0
 

Accepted Solution

by:
patd1 earned 0 total points
ID: 40538173
I used @raise_error and raised error if validation_status <> 1

This works for me.

Thank you for your help.
0
 

Author Closing Comment

by:patd1
ID: 40561569
setting @raise error worked.
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question