Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 SQL Agent Job step
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

332 Posts

Posted - 11/19/2013 :  15:19:07  Show Profile  Reply with Quote
we have a SQL Server agent job which has 2 steps

step 1- type is SSIS package it will fix the sync issues between OLTP and Reporting DB. Basically it is a ETL job
Step 2- send error email via sp_send_dbmail incase of job failure. added t-sql script

Now I want to add a step first...

the step is - query data from a table if it returns NO rows then go to next step
if returns rows donot go to next step

select * from table1 where CoulmnID ='' --Ensure it returns no rows.

HOW to add this step to job? any thoughts? thanks

Almighty SQL Goddess

38200 Posts

Posted - 11/19/2013 :  15:20:12  Show Profile  Visit tkizer's Homepage  Reply with Quote
Use the RAISERROR command to raise an error when it returns data:

IF EXISTS (select ...)

Then have the job step quit the job on failure of that step.

Tara Kizer
SQL Server MVP since 2007
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 11/20/2013 :  02:13:22  Show Profile  Reply with Quote
Actually you could do it all within same SSIS package itself. Thats the purpose of control flow engine. you can use SentMail task and link to your current sync step on failure to send error mail in case of failure. you can also add execute sql task to check count of rows and based on count determine next task to be executed by using expression based precedence constraint. So you'll just have single step in sql job and you do all control sequence action inside control flow of the package.

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000