IF EXISTS (SELECT * FROM SYS.views WHERE NAME = 'V_EST_PROD_CPL_TRIB_FORN')
BEGIN
	DROP VIEW V_EST_PROD_CPL_TRIB_FORN
END

GO
--select * from V_EST_PROD_CPL_TRIB_FORN
CREATE VIEW
	V_EST_PROD_CPL_TRIB_FORN
AS
SELECT
	T.CD_EMP
	,T.CD_REGIAO_FISCAL
	,T.CD_FORN
	,T.CD_PROD
	,T.CD_TRIB
	,T.TP_MOV
	,T.TP_TRANSA
	,T.PERC_RED
	,T.TP_SUBS
	,T.VLR_PAUTA_IVA
	,T.PERC_ICMS
	,T.TP_RED_BASE_IMP
	,T.PERC_ICMS_EST
	,T.PERC_RED_SUBS_TRIB
	,T.PERC_RED_ESTORNO
	,T.DT_CAD
	,T.CD_USU
	,T.CST_PIS
	,T.CST_COFINS
	,T.PERC_REPASSE
	,T.PERC_IBPT
	,RF.CD_FILIAL
FROM
	EST_PROD_PRC_REGIAO_FISCAL_TRIB_FORN T
	INNER JOIN PRC_REGIAO_FISCAL_PRC_FILIAL RF ON 
		T.CD_EMP = RF.CD_EMP
		AND T.CD_REGIAO_FISCAL = RF.CD_REGIAO_FISCAL
