If you cut the nails holding one of the corner studs to the bottom plate and the top plate with a Sawzall, you can use a flat bar (or a flat bar plus a wrecking bar) to pull the stud off the sheathing nails. Either re-use the stud, or buy a new stud, and install the stud with toenails as shown in the link I provided in Comment #51 (this link: Outside corner detail). 

A. You can use closed-cell spray foam that way if you want, although you should realize that the spray foam will prevent the roof sheathing from drying inward. This approach should only be used if the roof sheathing is bone dry, because it will never dry when sandwiched in this manner. Most building scientists would prefer to see fiberglass rather than closed-cell spray foam under the roof sheathing in this type of assembly.
Spray foam is a chemical product created by two materials, isocyanate and polyol resin, which react when mixed with each other and expand up to 30-60 times its liquid volume after it is sprayed in place. This expansion makes it useful as a specialty packing material which forms to the shape of the product being packaged and produces a high thermal insulating value with virtually no air infiltration.
This is more common with closed cell foam, but it happens with open cell foam, too. Since closed cell foam has a higher R-value per inch, installers generally spray 2" in walls and 3" in rooflines to meet the energy code requirements of R-13 and R-19, respectively. (I'm not going to dive into the energy code here, but these numbers apply to many climate zones, the latter being allowed under the UA tradeoffs rule. See the Energy Nerd's blog on this topic if you want to argue.)
In addition, it's difficult for an inexperienced installer to evenly spread the insulation foam over a surface. Miissing spots can leave holes and gaps for cold air to get through. Proceed with this project yourself only if you're doing a small insulation project -- such as installing foam in a crawl space or around your plumbing. Leave larger projects like the attic, basement or garage to the professional insulation contractors. Insulation professionals have the tools, equipment and background knowledge necessary. Moreover, they know how to accurately price insulation, whereas you could inaccurately budget for a DIY project and end up paying significantly more. Don't take the medical, physical or financial risks that come with pursuing this as a DIY project unless you're absolutely certain you have the skills.
It also has a great waterproofing ability that can shield the roof’s membrane from water and moisture damage. You can also count on the liquid roof coating for its outstanding performance for a wide range of applications and uses. This product can be used at tears and seams as well as in sealing air conditioners and venting systems and anywhere else where rubberized coating is needed.

Spray Foam Roof Insulation