sql server - SQL script that loops jobs for parallel execution -


i working on process load data oracle sql server using attunity connector in ssis. there around 50 tables need load , have created job each of them can load them in parallel. based on server resources, can run 10 @ time. have script have been working isn't working correctly because fires 10 jobs , quits. need script loop through 50 jobs (start ps_) , run 10.

declare @a int  set @a=0  declare @jobname nvarchar(200)  -- checks if there 10 jobs running  while ((@a <10) , (  			(select count(*) msdb.dbo.sysjobs   			inner join msdb.dbo.sysjobactivity b   				on a.job_id = b.job_id  			where start_execution_date not null   			and stop_execution_date null   			and substring (name, 1,3) = 'ps_')<= 10))  begin  	set @jobname = null  	--loops through fetch 1 non-running job @ time , fetches upto 10 jobs   	select top 1 @jobname = name  	from msdb.dbo.sysjobs x  	where substring (x.name, 1,3) = 'ps_'   	and  	--checks job did not run today , running.  	name in (  			select name  msdb.dbo.sysjobs c   			left outer join (select max(start_execution_date) start_execution_date ,job_id    							from msdb.dbo.sysjobactivity   							group job_id) b   			on b.job_id=c.job_id   	where cast(isnull(start_execution_date,'01/01/1900') date) < cast(getdate()as date))  	select @jobname    	if (@jobname not null)  		begin  			exec msdb.dbo.sp_start_job @job_name=@jobname  			--select @jobname  		end  		waitfor delay '00:00:02'  		set @a=@a+1  end

change while loop condition check if there jobs haven't run yet today. query how many of jobs executing. if more 10 execute waitfor delay; otherwise, start next job. end loop.

also might want add clause of job queries. i've been bit before.

where a.session_id = (select top 1 session_id msdb.dbo.syssessions order agent_start_date desc) 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -