IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE OBJECT_ID = OBJECT_ID(N'[V_EST_NF_SAI_DUPLICATAS]'))
	DROP VIEW [dbo].[V_EST_NF_SAI_DUPLICATAS]
GO

CREATE  VIEW [dbo].[V_EST_NF_SAI_DUPLICATAS]
AS
SELECT     
	dbo.EST_NF_SAI.CD_EMP, 
	dbo.EST_NF_SAI.CD_FILIAL, dbo.EST_NF_SAI.CD_PED, dbo.EST_NF_SAI.CD_NF, dbo.EST_NF_SAI.NF_NF, 
                      dbo.EST_NF_SAI.CD_CLI, dbo.PRC_GRP_ECON_PRC_FILIAL.CD_GRP_ECON, dbo.EST_NF_SAI.DT_EMI_NF, dbo.EST_NF_SAI.VLR_NF
FROM         dbo.EST_NF_SAI INNER JOIN
                      dbo.GLB_MOV_OP ON dbo.EST_NF_SAI.CD_NT_MOV = dbo.GLB_MOV_OP.CD_MOV_OP INNER JOIN
                      dbo.PRC_GRP_ECON_PRC_FILIAL ON dbo.EST_NF_SAI.CD_EMP = dbo.PRC_GRP_ECON_PRC_FILIAL.CD_EMP AND 
                      dbo.EST_NF_SAI.CD_FILIAL = dbo.PRC_GRP_ECON_PRC_FILIAL.CD_FILIAL
WHERE     (NOT EXISTS
                          (SELECT     CD_EMP
                            FROM          RC_DEB_EST_NF_SAI
                            WHERE      EST_NF_SAI.CD_EMP = RC_DEB_EST_NF_SAI.CD_EMP AND EST_NF_SAI.CD_FILIAL = RC_DEB_EST_NF_SAI.CD_FILIAL AND 
                                                   EST_NF_SAI.CD_NF = RC_DEB_EST_NF_SAI.CD_NF)) 
	AND (dbo.GLB_MOV_OP.TP_MOV_OP_TRANSA = 1) 
GO


