/****** Object:  Trigger [TRG_EST_NF_ENT_IT_PIS_COFINS]    Script Date: 10/10/2013 08:58:52 ******/
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_EST_NF_SAI_IT_PIS_COFINS]'))
DROP TRIGGER [dbo].[TRG_EST_NF_SAI_IT_PIS_COFINS]
GO
GO
CREATE TRIGGER [dbo].[TRG_EST_NF_SAI_IT_PIS_COFINS] ON [dbo].[EST_NF_SAI_IT] 
FOR INSERT
AS
	UPDATE
		i
	SET
		i.PIS_COFINS=p.PIS_COFINS,
		i.LISTA_PROD = p.LISTA_PROD,
		i.TIPO_TRIBUTACAO_PIS_COFINS = isnull(p.TIPO_TRIBUTACAO_PIS_COFINS,0),
		SIGLA_EXCECAO_PIS_COFINS=ISNULL(p.SIGLA_EXCECAO_PIS_COFINS,''),
		FLAG_EXCECAO_PIS_COFINS=ISNULL(p.FLAG_EXCECAO_PIS_COFINS,0),
		FLAG_PROD_CESTA_BASICA=ISNULL(p.FLAG_PROD_CESTA_BASICA,0)		
	FROM
		EST_NF_SAI_IT i INNER JOIN  INSERTED  ON
		i.CD_EMP = INSERTED.CD_EMP AND
		i.CD_FILIAL = INSERTED.CD_FILIAL AND
		i.CD_NF = INSERTED.CD_NF AND
		i.CD_PROD = INSERTED.CD_PROD 
		INNER JOIN EST_PROD p ON
		INSERTED.CD_EMP = p.CD_EMP AND
		INSERTED.CD_PROD = p.CD_PROD
