/*
SELECT * FROM EST_PROD_TBL_DESC_QTDE
SELECT * FROM EST_PROD_TBL_DESC_QTDE_EST_PROD
SELECT * FROM EST_PROD_TBL_DESC_QTDE_PRC_FILIAL
*/

IF OBJECT_ID('V_EST_PROD_TBL_DESC_QTDE_CARGA_PDV') IS NOT NULL
	DROP VIEW V_EST_PROD_TBL_DESC_QTDE_CARGA_PDV
GO

CREATE VIEW V_EST_PROD_TBL_DESC_QTDE_CARGA_PDV
AS
SELECT * FROM EST_PROD_TBL_DESC_QTDE WHERE DT_FIM >= GETDATE()

GO

IF OBJECT_ID('V_EST_PROD_TBL_DESC_QTDE_EST_PROD_CARGA_PDV') IS NOT NULL
	DROP VIEW V_EST_PROD_TBL_DESC_QTDE_EST_PROD_CARGA_PDV
GO

CREATE VIEW V_EST_PROD_TBL_DESC_QTDE_EST_PROD_CARGA_PDV
AS
SELECT
TBL_FIL.CD_EMP,
TBL_FIL.CD_FILIAL,
TBL_FIL.CD_TBL_DESC_QTDE,
TBL_PROD.CD_PROD,
TBL_PROD.FLAG_DESC_QTDE

FROM	EST_PROD_TBL_DESC_QTDE TBL
INNER	JOIN EST_PROD_TBL_DESC_QTDE_PRC_FILIAL TBL_FIL
ON		TBL.CD_EMP = TBL_FIL.CD_EMP AND TBL.CD_TBL_DESC_QTDE = TBL_FIL.CD_TBL_DESC_QTDE
INNER	JOIN EST_PROD_TBL_DESC_QTDE_EST_PROD TBL_PROD
ON		TBL_FIL.CD_EMP = TBL_PROD.CD_EMP AND TBL_FIL.CD_TBL_DESC_QTDE = TBL_PROD.CD_TBL_DESC_QTDE
WHERE	TBL.DT_FIM >= GETDATE();