
/****** Object:  StoredProcedure [dbo].[P_EST_FECHA_PROC_MOV_EST_PROD_CPL_REPROC_CUSTO_ALL]    Script Date: 12/19/2013 17:34:39 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_EST_FECHA_PROC_MOV_EST_PROD_CPL_REPROC_CUSTO_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_EST_FECHA_PROC_MOV_EST_PROD_CPL_REPROC_CUSTO_ALL]
GO

CREATE PROCEDURE [dbo].[P_EST_FECHA_PROC_MOV_EST_PROD_CPL_REPROC_CUSTO_ALL] (@CD_EMP INT=1)
AS
 --Versao 2456
	DECLARE @CD_FILIAL AS INT 
	
	DECLARE cFilial CURSOR FAST_FORWARD READ_ONLY FOR 
	SELECT  
	 	CD_FILIAL
	FROM 
		PRC_FILIAL
	WHERE 
		CD_EMP = @CD_EMP
	ORDER BY CD_FILIAL
	
	OPEN cFilial
	FETCH NEXT FROM cFilial INTO @CD_FILIAL

	WHILE @@FETCH_STATUS=0
	BEGIN
		
		PRINT 'Aplicacao do custo médio e gerencial na EST_PROD_CPL - Filial.: ' + CONVERT(VARCHAR, @CD_FILIAL) + ' Time : ' + CONVERT(VARCHAR,GETDATE(),108)  
		EXECUTE P_EST_FECHA_PROC_MOV_EST_PROD_CPL_REPROC_CUSTO @CD_EMP, @CD_FILIAL;

		FETCH NEXT FROM  cFilial INTO @CD_FILIAL 
	END
	CLOSE cFilial
	DEALLOCATE cFilial

GO


