/****** Object:  StoredProcedure [dbo].[P_EST_PROD_SOMATORIA_MTZ_EXECUTE_ALL]    Script Date: 02/10/2014 18:47:24 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_EST_PROD_SOMATORIA_MTZ_EXECUTE_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_EST_PROD_SOMATORIA_MTZ_EXECUTE_ALL]
GO 
/****** Object:  StoredProcedure [dbo].[P_EST_PROD_SOMATORIA_MTZ]    Script Date: 02/10/2014 18:47:24 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO 

/*
	Ir ao job manutencia di?ria no step M?dia F - Somatorio Matriz e trocar o conteudo
	do Step para EXEC P_EST_PROD_SOMATORIA_MTZ_EXECUTE_ALL
*/

-- EXECUTE P_EST_PROD_SOMATORIA_MTZ_EXECUTE_ALL
CREATE PROCEDURE [dbo].[P_EST_PROD_SOMATORIA_MTZ_EXECUTE_ALL] (@CD_PROD_PARAM  INT=0) AS
SET NOCOUNT ON;
PRINT 'Processamento de somatoria MediaF Depositos' 
DECLARE @CD_FILIAL_DEPO AS INT
DECLARE @FLAG_DESATIVADO AS INT
DECLARE Depositos CURSOR FAST_FORWARD FOR SELECT CD_FILIAL,FLAG_DESATIVADO FROM PRC_FILIAL_DEPOSITO 
OPEN Depositos
FETCH NEXT FROM Depositos INTO @CD_FILIAL_DEPO,@FLAG_DESATIVADO
WHILE @@FETCH_STATUS=0
  begin
	PRINT	'  Analise deposito ' + convert(varchar(5), @CD_FILIAL_DEPO) + 
			' (' + CONVERT(VARCHAR(8), GETDATE(), 114) + ')...'
		EXECUTE dbo.P_EST_PROD_SOMATORIA_MTZ  @CD_FILIAL_DEPO, @CD_PROD_PARAM,@FLAG_DESATIVADO
	FETCH NEXT FROM Depositos INTO @CD_FILIAL_DEPO,@FLAG_DESATIVADO
  end
PRINT 'Conclu?do.'
CLOSE Depositos
DEALLOCATE Depositos
GO