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

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 SQL Agent Job step

Author  Topic 

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2013-11-19 : 15:19:07
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

38200 Posts

Posted - 2013-11-19 : 15:20:12
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

52326 Posts

Posted - 2013-11-20 : 02:13:22
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
   

- Advertisement -