IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_SNGPC_MOVIMENTOS_PENDENTE_EXECUTE_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_SNGPC_MOVIMENTOS_PENDENTE_EXECUTE_ALL]
GO
--EXEC P_SNGPC_MOVIMENTOS_PENDENTE_EXECUTE_ALL 
CREATE PROCEDURE [dbo].[P_SNGPC_MOVIMENTOS_PENDENTE_EXECUTE_ALL] AS
/*
	Esta procedure e processada dentro da procedure de pendencia de entrada
	"P_EST_PROD_PENDENCIA_ENTRADA"
*/
SET NOCOUNT ON
DECLARE @CD_FILIAL INT
DECLARE @CD_EMP INT

DECLARE Sngpcfiliais CURSOR FAST_FORWARD FOR 
		SELECT CD_EMP,CD_FILIAL FROM PRC_FILIAL ORDER BY CD_FILIAL
		
		
OPEN Sngpcfiliais
FETCH NEXT FROM Sngpcfiliais INTO @CD_EMP,@CD_FILIAL
	WHILE @@FETCH_STATUS=0
	  begin
		PRINT 'Filial ' + CONVERT(VARCHAR, @CD_FILIAL) 
		
		EXEC P_SNGPC_MOVIMENTOS_PENDENTE @CD_EMP,@CD_FILIAL

		FETCH NEXT FROM Sngpcfiliais INTO @CD_EMP,@CD_FILIAL
	  end

PRINT 'Concluido.'
CLOSE Sngpcfiliais;
DEALLOCATE Sngpcfiliais;


