select nfcompras.*, totitens.vtotitem from nfcompras,(select fknunfcompra,SUM(qtcomprada*vlunitario) AS vtotitem 
						         from nfcomprasitens group by fknunfcompra order by fknunfcompra) AS totitens
         WHERE nfcompras.pknunfcompra=totitens.fknunfcompra and
		       vltotalnfcompra<>totitens.vtotitem;

update nfcompras set vltotalnfcompra=0 where pknunfcompra=1;
