The Nasdaq fell on Friday, halting a 12-day run-up, following Microsoft Corp's disappointing quarterly results, but gains in pharmaceutical and energy shares lifted the Dow and the S&P 500 to fresh 8-month closing highs.

Microsoft shares slid 8.3 percent to $23.45, a day after the software maker posted quarterly revenue below Wall Street's estimates. Web retailer Inc also missed sales expectations, sending its stock down 7.9 percent to $86.49.

The results cast a cloud over what is so far shaping up to be a stronger-than-expected second-quarter earnings season.

Even so, investors took Wall Street's initial drop on Friday as an opportunity to scoop up shares in other sectors, including energy and defensive plays such as big pharmaceuticals and utilities.

Microsoft is going through a product transition and no great visibility on the Windows franchise, but in general, the tone this quarter for a good many companies has been strong, said Owen Fitzpatrick, head of the U.S. equity group at Deutsche Bank Private Wealth Management in New York.

We are not probably going to see a major shift here in the negative direction, so it's probably going to be overall positive for earnings season.

The Dow Jones industrial average <.DJI> rose 23.95 points, or 0.26 percent, to 9,093.24. The Standard & Poor's 500 Index <.SPX> advanced 2.97 points, or 0.30 percent, to 979.26. But the Nasdaq Composite Index <.IXIC> shed 7.64 points, or 0.39 percent, to 1,965.96.

Microsoft was the top drag on both the Dow and the Nasdaq. was the Nasdaq's second-worst performer.

The Nasdaq's 12-day winning streak was its longest unbroken run since 1992.

All three major U.S. stock indexes scored a second straight weekly advance, with the Dow rising 4 percent, the S&P 500 gaining 4.1 percent and the Nasdaq climbing 4.2 percent.

For the day, both the Dow and the S&P 500 hit their highest closes since early November 2008.

The broad market's gains were curbed by a report showing U.S. consumer sentiment waned in late July to its lowest reading since April, according to the Reuters/University of Michigan Surveys of Consumers.

Johnson & Johnson , up 2.1 percent at $61.51, provided the top boost to the Dow, followed by Merck & Co , up 2.5 percent at $30.99. The AMEX Pharmaceuticals index <.DRG> rose 1.4 percent.

Chevron Corp climbed 0.8 percent to $68.43 after U.S. front-month crude oil gained 89 cents, or 1.3 percent, to settle at $68.05 a barrel on the New York Mercantile Exchange. The S&P energy index <.GSPE> rose 1 percent.

In other earnings-related news, tool manufacturer Black and Decker Corp raised its full-year profit view, sending its shares up 10.1 percent to $37.13.

(Editing by Jan Paschal)