IF OBJECT_ID('V_PRC_FILIAL_SRV_TELE') IS NOT NULL
BEGIN
	DROP VIEW V_PRC_FILIAL_SRV_TELE;
END

GO
CREATE VIEW [dbo].[V_PRC_FILIAL_SRV_TELE]
AS
SELECT
  PRC_FILIAL_SRV_TELE.CD_EMP,
  PRC_FILIAL_SRV_TELE.CD_FILIAL,
  PRC_FILIAL_SRV_TELE.CD_SRV,
  PRC_FILIAL_SRV_TELE.SRV,
  0 AS OFFLINE,
  CONVERT(INT,ISNULL(CONFIG.TP_CONEXAO,0)) AS TP_CONEXAO,
  '1.0' as versao
FROM PRC_FILIAL_SRV_TELE LEFT JOIN 
    (SELECT CD_EMP,CD_FILIAL,ISNULL(VALOR,0) AS TP_CONEXAO 
	   FROM PRC_FILIAL_CONFIG 
	   WHERE PRC_FILIAL_CONFIG.CD_CHAVE = 'FLAG_PRC_FILIAL_SRV_TELE') AS CONFIG ON
    CONFIG.CD_EMP=PRC_FILIAL_SRV_TELE.CD_EMP AND
    CONFIG.CD_FILIAL=PRC_FILIAL_SRV_TELE.CD_FILIAL
