IF EXISTS(select 1 from syscolumns where id = object_id('PG_CRED_NF') and name = 'CD_NF')
BEGIN
	UPDATE PNF
	SET CD_NF = E.CD_NF
	from PG_CRED_NF PNF
	INNER JOIN EST_NF_ENT E ON E.NR_NF = PNF.NR_NF AND E.CD_FILIAL = PNF.CD_FILIAL
	where PNF.CD_NF = 0
END