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 2008 Forums
 SQL Server Administration (2008)
 SQL Agent Job step
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

laddu
Constraint Violating Yak Guru

USA
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

tkizer
Almighty SQL Goddess

USA
37287 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 ...)
RAISERROR

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

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.08 seconds. Powered By: Snitz Forums 2000