IF EXISTS 
( 
    SELECT * 
    FROM sys.views 
    WHERE object_id = OBJECT_ID(N'[dbo].[V_EST_PROD_CPL_LOTE_TENTACLE]') 
) 
    DROP VIEW [dbo].V_EST_PROD_CPL_LOTE_TENTACLE; 
GO 
CREATE VIEW [dbo].V_EST_PROD_CPL_LOTE_TENTACLE 
AS 
     SELECT CD_EMP 
,CD_FILIAL 
,CD_LOTE 
,CD_PROD 
,NR_LOTE 
,CONVERT (DATE,DT_VALID )as DT_VALID
,QTDE_PROD as QTDE_LOTE
,QTDE_PROD
,DT_FABR 
,DT_CAD 
,GETDATE() AS DT_HR_CARGA
,CD_AGREGADOR
     FROM EST_PROD_CPL_LOTE 
     WHERE CD_EMP = 1 
GO 
IF EXISTS 
( 
    SELECT * 
    FROM sys.views 
    WHERE object_id = OBJECT_ID(N'[dbo].[V_EST_PROD_FABRIC_TENTACLE]') 
) 
    DROP VIEW [dbo].V_EST_PROD_FABRIC_TENTACLE; 
GO 
CREATE VIEW [dbo].V_EST_PROD_FABRIC_TENTACLE 
AS 
     SELECT CD_FABRIC, 
NM_FABRIC 
     FROM EST_PROD_FABRIC 
     WHERE CD_EMP = 1 
GO 
IF EXISTS 
( 
    SELECT * 
    FROM sys.views 
    WHERE object_id = OBJECT_ID(N'[dbo].[V_PRC_FILIAL_SRV_ORC]') 
) 
    DROP VIEW [dbo].V_PRC_FILIAL_SRV_ORC; 
GO 
CREATE VIEW [dbo].[V_PRC_FILIAL_SRV_ORC] 
AS 
SELECT 
    PRC_FILIAL_SRV_ORC.CD_EMP, 
    PRC_FILIAL_SRV_ORC.CD_FILIAL, 
    PRC_FILIAL_SRV_ORC.CD_SRV, 
    PRC_FILIAL_SRV_ORC.SRV, 
    0 AS OFFLINE, --- 
    CAST(ISNULL(CONFIG.TP_CONEXAO,0) AS INT) AS TP_CONEXAO	
FROM	PRC_FILIAL_SRV_ORC 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_ORC') AS CONFIG ON 
    CONFIG.CD_EMP=PRC_FILIAL_SRV_ORC.CD_EMP AND 
    CONFIG.CD_FILIAL=PRC_FILIAL_SRV_ORC.CD_FILIAL 
GO 
IF EXISTS 
( 
    SELECT * 
    FROM sys.views 
    WHERE object_id = OBJECT_ID(N'[dbo].V_EST_PROD_TBL_DESC_EST_PROD_CARGA_TENTACLE') 
) 
    DROP VIEW [dbo].[V_EST_PROD_TBL_DESC_EST_PROD_CARGA_TENTACLE]; 
GO 
CREATE VIEW [dbo].[V_EST_PROD_TBL_DESC_EST_PROD_CARGA_TENTACLE] 
AS 
SELECT 
TBL_FIL.CD_EMP, 
TBL_FIL.CD_TBL_DESC, 
TBL_PROD.CD_PROD, 
TBL_PROD.PERC_DESC, 
TBL_PROD.PERC_DESC_MAX, 
TBL_PROD.PERC_DESC_LIMITE, 
TBL_PROD.PERC_AUMENTO, 
GETDATE() AS DT_HR_CARGA 
FROM	
V_EST_PROD_TBL_DESC_CARGA_TENTACLE TBL 
INNER	JOIN EST_PROD_TBL_DESC_PRC_FILIAL TBL_FIL ON	
TBL.CD_EMP	= TBL_FIL.CD_EMP AND 
TBL.CD_TBL_DESC = TBL_FIL.CD_TBL_DESC 
INNER	JOIN EST_PROD_TBL_DESC_EST_PROD TBL_PROD ON	
TBL_FIL.CD_EMP	= TBL_PROD.CD_EMP AND 
TBL_FIL.CD_TBL_DESC = TBL_PROD.CD_TBL_DESC 
WHERE 
TBL.CD_EMP = 1 
AND TBL_PROD.CD_EMP =1 
GO 