/****** Object:  StoredProcedure [dbo].[P_EST_PROD_REAVALIAR_CURVA]    Script Date: 10/07/2012 18:09:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_EST_PROD_REAVALIAR_CURVA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_EST_PROD_REAVALIAR_CURVA]
GO
GO


CREATE  PROCEDURE [dbo].[P_EST_PROD_REAVALIAR_CURVA] @CD_FILIL_PAR INT=0 AS
DECLARE @AGORA  DATETIME;
SELECT	@AGORA = CONVERT(CHAR(10),GETDATE(),120)

PRINT 'Processamento de Curvas' 

DECLARE @CD_FILIAL  AS INT
DECLARE ljs CURSOR 
	FAST_FORWARD FOR 
	SELECT 
		CD_FILIAL 
		FROM PRC_FILIAL
		 WHERE CD_EMP=1
		 AND CD_FILIAL = CASE WHEN @CD_FILIL_PAR=0 THEN CD_FILIAL ELSE @CD_FILIL_PAR END
		
OPEN ljs
FETCH NEXT FROM ljs INTO @CD_FILIAL

WHILE @@FETCH_STATUS=0
  begin
	PRINT	'  Gerandoa curva para a filial  ' + convert(varchar(5), @CD_FILIAL ) + 
			' (' + CONVERT(VARCHAR(8), GETDATE(), 114) + ')...'
		EXECUTE P_EST_PROD_REAVALIAR_CURVA_FILIAL 1,@CD_FILIAL;
	FETCH NEXT FROM ljs INTO @CD_FILIAL
  end
   
  UPDATE
		EST_ARV_MD_F_GRP_PARAM_CURVA
	SET
		FCURVA_ULT_ATU=@AGORA;
		 
	PRINT 'Atualizou  a tabela  EST_ARV_MD_F_GRP_PARAM_CURVA - Hora : '+ CONVERT(VARCHAR, GETDATE(),108);
 
 
PRINT 'Concluído.'
CLOSE ljs
DEALLOCATE ljs






GO


