When or is it NEC code compliant to upgrade a 2-wire circuit, by adding a third prong equipment ground from a nearby cold water pipe?
A different case of borrowing a ground from a nearby circuit is covered at: Is it OK to borrow a ground wire from a different circuit? (the short answer is it's now OK in the USA).
I am aware that this method of grounding was once common. However a water pipe ground is subject to issues in future partial re-plumbing, which may involve isolating pipe with a dielectric union: