It's really two separate transactions - dealers build empires off of confusing consumers and blurring this fact. The amount they give you for a trade-in they should be willing to just cut you a check and leave out the fact that you are buying a vehicle from them. Again though, it's all smoke, mirrors and deception to confuse people.
As mentioned numerous times on the thread, try to sell private party. As a general rule you should be able to instantly sell a vehicle on Craigslist for 10% more than the dealer will offer you as a trade.