/****** Object:  StoredProcedure [dbo].[P_PDV_VD_CHQS_APLICAR_CHQS_TIPO_ALL]    Script Date: 11/28/2013 09:36:38 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_PDV_VD_CHQS_APLICAR_CHQS_TIPO_ALL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_PDV_VD_CHQS_APLICAR_CHQS_TIPO_ALL]
GO
GO
--EXEC P_PDV_VD_CHQS_APLICAR_CHQS_TIPO_ALL 1,'2018-01-01','2019-12-31'
CREATE PROCEDURE P_PDV_VD_CHQS_APLICAR_CHQS_TIPO_ALL @CD_EMP INT, @DT_INI DATETIME, @DT_FIM DATETIME
AS
SET NOCOUNT ON
DECLARE @CD_FILIAL INT
DECLARE ProcFilialChqs CURSOR FAST_FORWARD FOR 
SELECT
	CD_FILIAL
FROM
	PRC_FILIAL
WHERE
	CD_EMP=@CD_EMP

OPEN ProcFilialChqs;
FETCH NEXT FROM ProcFilialChqs INTO @CD_FILIAL;
WHILE @@FETCH_STATUS = 0
    BEGIN
		PRINT CONVERT(VARCHAR(10),@CD_FILIAL)
		
		EXEC P_PDV_VD_CHQS_APLICAR_CHQS_TIPO @CD_EMP,@CD_FILIAL,@DT_INI,@DT_FIM

		FETCH NEXT FROM ProcFilialChqs INTO @CD_FILIAL;
    END;
PRINT 'CONCLUIDO.';
CLOSE ProcFilialChqs;
DEALLOCATE ProcFilialChqs;