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

SELECT     PDV_VD.CD_EMP, PDV_VD.CD_FILIAL , PDV_VD.CD_VD , PDV_VD.DT_VD , 
ISNULL(SUM(VLR_BASE_PIS ),0) BASE_PIS_NF ,
ISNULL(SUM(VLR_PIS ),0) PIS_NF ,
ISNULL(SUM(VLR_BASE_COFINS ),0) BASE_COFINS_NF ,
ISNULL(SUM(VLR_COFINS ),0) COFINS_NF 

FROM PDV_VD_IT  INNER JOIN PDV_VD ON 
		PDV_VD_IT.CD_EMP  =  PDV_VD.CD_EMP 
		AND PDV_VD_IT.CD_FILIAL  = PDV_VD.CD_FILIAL 
		AND PDV_VD_IT.CD_VD = PDV_VD.CD_VD 
		WHERE  PDV_VD.ST_VD = 0 
		       AND PDV_VD_IT.ST_IT = 1
 
GROUP BY  PDV_VD.CD_EMP, PDV_VD.CD_FILIAL , PDV_VD.CD_VD ,PDV_VD.DT_VD
