CREATE PROC [dbo].[sp_ExecuteJobProcs]
AS

DECLARE @recId INT
		,@customerDB VARCHAR(50)
		,@procName VARCHAR(50)
		,@procParams VARCHAR(250)

DECLARE jobCursor CURSOR FOR
	
	SELECT	J.recId
			,J.customerDB
			,J.procName
			,J.procParams
	FROM	[Framework_Evol-1].[dbo].pal_JobProcs J
	WHERE	todo = 1

	OPEN jobCursor      
		FETCH NEXT FROM jobCursor INTO @recId,@customerDB,@procName,@procParams
    
	WHILE @@FETCH_STATUS = 0 
	BEGIN 
		DECLARE @query VARCHAR(MAX)

		SET	@query = 'EXEC ['+@customerDB+'].[dbo].['+@procName+'] '+@procParams+''

		--PRINT @query
		EXEC(@query)

		UPDATE	J
			SET	todo = 0
		FROM	[Framework_Evol-1].[dbo].pal_JobProcs J
		WHERE	recId = @recId

		FETCH NEXT FROM jobCursor INTO @recId,@customerDB,@procName,@procParams       
	END   

CLOSE jobCursor      
DEALLOCATE jobCursor  

