/****** Object:  StoredProcedure [dbo].[P_RC_VD_CONV_GERAR_VENDAS_CONVENIO_ALL]    Script Date: 03/26/2014 10:46:14 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_RC_VD_CONV_GERAR_VENDAS_CONVENIO_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_RC_VD_CONV_GERAR_VENDAS_CONVENIO_ALL]
GO
GO
-- exec P_RC_VD_CONV_GERAR_VENDAS_CONVENIO_ALL '2019-11-01'
CREATE PROCEDURE P_RC_VD_CONV_GERAR_VENDAS_CONVENIO_ALL  @DT_PROC DATETIME=NULL
WITH ENCRYPTION
AS
SET NOCOUNT ON
	DECLARE @CD_FILIAL AS INT
	DECLARE @CD_EMP INT 

	IF @DT_PROC IS NULL
	BEGIN
		SET @DT_PROC=CONVERT(CHAR(10),GETDATE(),112)
	END

    DECLARE CfiliaisConvenioGerar CURSOR FAST_FORWARD FOR 
		SELECT 
			CD_EMP,
			CD_FILIAL
		FROM	
			PRC_FILIAL
		ORDER BY 
			CD_FILIAL
	
	OPEN CfiliaisConvenioGerar

	FETCH NEXT FROM CfiliaisConvenioGerar INTO @CD_EMP,@CD_FILIAL
		WHILE @@FETCH_STATUS=0
		  begin
			PRINT 'Filial ' + CONVERT(VARCHAR, @CD_FILIAL)
				exec P_RC_VD_CONV_GERAR_VENDAS_CONVENIO @CD_EMP,@CD_FILIAL,@DT_PROC
			FETCH NEXT FROM CfiliaisConvenioGerar INTO @CD_EMP,@CD_FILIAL
		  end

PRINT 'Concluido.'
CLOSE CfiliaisConvenioGerar;
DEALLOCATE CfiliaisConvenioGerar;
		