IF EXISTS(SELECT 1 FROM SYS.TABLES WHERE NAME = 'PRC_FILIAL_CONFIG' )
BEGIN 
    INSERT INTO PRC_FILIAL_CONFIG  (cd_emp,cd_filial,CD_CHAVE,VALOR,cd_usu,DT_ULT_ALT) 
	SELECT 1,CD_FILIAL,'WEB_SERVICE_ORCAMENTO_TIMEOUT','12000',1, GETDATE()
	FROM PRC_FILIAL P
	WHERE NOT EXISTS (SELECT 1 FROM PRC_FILIAL_CONFIG C
					  WHERE C.CD_FILIAL = P.CD_FILIAL
					  AND C.CD_CHAVE = 'WEB_SERVICE_ORCAMENTO_TIMEOUT')
	 
	UPDATE PRC
	SET VALOR = '12000'
	FROM PRC_FILIAL_CONFIG PRC
	WHERE CD_CHAVE = 'WEB_SERVICE_ORCAMENTO_TIMEOUT'
	AND VALOR <> '12000'
END
