/****** Object:  View [dbo].[V_EST_NF_SAI_DAR_IMPOSTO_GERADOS]    Script Date: 06/05/2013 11:24:02 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_EST_NF_SAI_DAR_IMPOSTO_GERADOS]'))
DROP VIEW [dbo].[V_EST_NF_SAI_DAR_IMPOSTO_GERADOS]
GO
GO
GO
CREATE VIEW  [dbo].[V_EST_NF_SAI_DAR_IMPOSTO_GERADOS] AS 
SELECT
	EST_NF_SAI_DAR.CD_EMP,
	EST_NF_SAI_DAR.CD_FILIAL,
	EST_NF_SAI_DAR.CD_NF,
	SUM(VLR_BASE_ICMS) AS VLR_BASE_ICMS,
	SUM(EST_NF_SAI_DAR_IT.VLR_ICMS) AS VLR_ICMS,
	SUM(VLR_BASE_SUBS) AS VLR_BASE_SUBS,
	SUM(VLR_ICMS_SUBS) AS VLR_ICMS_SUBS,
	EST_NF_SAI_DAR.UF AS UF_DEST
FROM EST_NF_SAI_DAR INNER JOIN 
	EST_NF_SAI_DAR_IT ON 
	EST_NF_SAI_DAR.CD_EMP = EST_NF_SAI_DAR_IT.CD_EMP 
	AND EST_NF_SAI_DAR.CD_FILIAL = EST_NF_SAI_DAR_IT.CD_FILIAL
	AND EST_NF_SAI_DAR.CD_NF = EST_NF_SAI_DAR_IT.CD_NF
	AND EST_NF_SAI_DAR.CD_DAR = EST_NF_SAI_DAR_IT.CD_DAR

GROUP BY
	EST_NF_SAI_DAR.CD_EMP,
	EST_NF_SAI_DAR.CD_FILIAL,
	EST_NF_SAI_DAR.CD_NF,
	EST_NF_SAI_DAR.UF

