There are various ways of doing it, but it depends on what frame you've got, the newer 9mm P229s use the same frame as the .40 P229 but the older guns use the P228 frame. The difference being the width of the magazine well.
With the older guns there are companies that made 9mm barrels for the .40, basically you just hope the rounds stay in the magazine and the barrel has a smaller hole down the middle.
But now... with the newer guns you can buy a new slide and barrel and magazine and do it properly! Only $600! Why bother...