Page 1 of 1

Excuting Job Conditionally

Posted: Wed Aug 19, 2009 5:44 am
by Vishal1982
Hi All,

I have two jobs say Job1 and Job2,and I want to Execute these jobs conditionally depending upon the rowcount of a table(Table1), which is stored separately in database and not used in either of Job1 and Job2.

For Example: If my Table1 contains zero records i.e. rowcount=0 ,then i want to execute Job1 and then Job2 and if my Table1 contains more than one record i.e rowcount >1 then want to execute Job2 directly without executing Job1.

Please help me to solve this problem.

Thanks,
Vishal J.

Posted: Wed Aug 19, 2009 5:54 am
by Sainath.Srinivasan
Several ways.

Simplest will be to run the sql command from command activity and decide on the return value.

Posted: Wed Aug 19, 2009 6:30 am
by Vishal1982
Hi,

I am new to this tool. By means of command activity I don't know where to use this count and how to use this,So Please clear me this command activity in detail or if possible provide with the another solution.

Thanks,
Vishal J.

Posted: Wed Aug 19, 2009 6:36 am
by ArndW
"Command Activity" lets you execute a shell command. This would be a SQL Command to your database to get the results from the table. This result can be check in the job sequence and can be used as the condition on whether or not to execute a job.

Posted: Wed Aug 19, 2009 6:41 am
by Sainath.Srinivasan
Btw, this is part of "Sequence" jobs.

You can also include a sub-query in job1 as

yourNormalQuery
where
not exists (select 1 from Table1)

This is assuming that your job does not overwrite or re-create anything.

Posted: Wed Aug 19, 2009 7:06 am
by chulett
A search for USERSTATUS or DSSetUserStatus will give you another approach if command line sql queries are out of your comfort zone.