If I enter an amount with code V in box 12 of the W-2, it doesn't carry directly to Schedule D or the 1040 return. What is code W used for?
Code V in box 12 of the W-2 indicates income from the exercise of nonstatutory stock options. Per IRS General Instructions for Forms W-2 and W-3:
Code V—Income from the exercise of nonstatutory stock option(s). Show the spread (that is, the fair market value of stock over the exercise price of option(s) granted to your employee with respect to that stock) from your employee’s (or former employee’s) exercise of nonstatutory stock option(s). Include this amount in boxes 1, 3 (up to the social security wage base), and 5.
As the amount is already reported in box 1 (wages, tips), which flows to line 7 of the 1040, there is no need for the amount in box 12 to flow to another section of or supporting form for the 1040.
On the W-2 box 12, Code W is for Employer Contributions to a Health Savings Account (HSA).
Form 1040 Instructions indicate it is supposed to appear on line 36:
Contributions to section 501(c)(18)(D) pension plans (see Pub. 525). Identify as “501(C)(18)(D)”.