I'd rule out the 40D, there's no competition between it and the 50D/D90.
Between the 50D and D90, it's a difficult choice. They are about the same age (okay, so the D90 is one
day younger), albeit neither are exactly what I'd call "cutting edge" either.
Where the 50D wins is in the build quality department, it's constructed out of a sturdy mag-alloy shell; much more durable than the D90's plastic. It also has more megapixels for large prints, a faster burst rate, plus a faster max shutter speed. However, the D90 is by no means a slouch. On the Nikon side you'll get better high ISO performance, a superior viewfinder, better AF, much
greater dynamic range, plus a video mode (it's 720p only, but at least it's an option).
They're really similar cameras, the D90 may have slightly better IQ (this could be my Nikon fanboy mentality speaking though), however the 50D has a few more MPs. the 50D has a better build, but the D90 has a video mode. What it will really come down to is feel or ergonomics, and the price. Go into your local camera store and try each body out, or if they don't have a D90 and 50D, just try a similar Nikon and Canon out. If you don't have a preference, let price be the deciding factor. If they're the same, flip a coin
they're both excellent cameras, and in the hands of a good photographer will produce stupendous images.