IF EXISTS
(
    SELECT *
    FROM sys.views
    WHERE object_id = OBJECT_ID(N'[dbo].V_EST_PROD_PRECO_DESC_QTDE_CPL_CARGA_TENTACLE')
)
    DROP VIEW [dbo].[V_EST_PROD_PRECO_DESC_QTDE_CPL_CARGA_TENTACLE];
GO


CREATE VIEW [dbo].[V_EST_PROD_PRECO_DESC_QTDE_CPL_CARGA_TENTACLE]
AS
     SELECT TBL_FIL.CD_EMP,
            TBL_FIL.CD_FILIAL,
            TBL_FIL.CD_PRECO_DESC_QTDE,
            TBL_PROD.CD_PROD,
            TBL_PROD.QT_PROD,
            TBL_PROD.QT_PROD_MAX,
            TBL_PROD.PERC_DESC_QTDE,
    GETDATE() DT_HR_CARGA
     FROM EST_PROD_PRECO_DESC_QTDE TBL
          INNER JOIN EST_PROD_PRECO_DESC_QTDE_PRC_FILIAL TBL_FIL ON TBL.CD_PRECO_DESC_QTDE = TBL_FIL.CD_PRECO_DESC_QTDE
          INNER JOIN EST_PROD_PRECO_DESC_QTDE_CPL TBL_PROD ON TBL_FIL.CD_EMP = TBL_PROD.CD_EMP
                                                              AND TBL_FIL.CD_PRECO_DESC_QTDE = TBL_PROD.CD_PRECO_DESC_QTDE
	WHERE TBL_FIL.CD_EMP = 1;
GO
