I have actually done this a few years ago. I had a sw9p and had purchased a 40v slide and barrel off of ebay.
The slide and barrel fit the 9mm frame perfectly. The problem was that the 40 magazines would not fit in the 9mm frame. The recoil springs are the same for both guns though.
The solution was to "bend" the feed lips of the 9mm mag wide enough so that it would feed the 40 s&w bullets. I did this with a 10 round mag which held 8 of the 40 bullets.
Doing this actually worked, but I can't recommend to anyone else. I don't think I ever shot more than a box of ammo through this configuration before I sold the gun. There were no signs of wear. I still have the slide and barrel mothballed in the holster box in the basement. The above posters are pretty much on the mark about buying a second gun. I eventually replaced that gun with a SW99 (in surprise - 40 s&w) and that gun is fantastic.
Disclaimer. If you attempt the above you do this on at your own risk.