17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7: Adding More to Our Queries<br />

These are just the highlights. The possibilities of different mixes and additional situations are positively<br />

endless.<br />

I can’t stress enough how important it is when in doubt — heck, even when you’re not<br />

in doubt but performance is everything — to make reasonable tests of competing solutions<br />

to a problem. Most of the time the blanket rules will be fine, but not always. By<br />

performing reasonable tests, you can be certain you’ve made the right choice.<br />

Summary<br />

The query options you learned back in Chapters 3 and 4 cover perhaps 80 percent or more of the query<br />

situations that you run into, but it’s that other 20 percent that can kill you. Sometimes the issue is whether<br />

you can even find a query that will give you the answers you need. Sometimes it’s that you have a particular<br />

query or sproc that has unacceptable performance. Whatever the case, you’ll run across plenty of<br />

situations where simple queries and joins just won’t fit the bill. You need something more and, hopefully,<br />

the options covered in this chapter have given you a little extra ammunition to deal with those tough<br />

situations.<br />

Exercises<br />

1. Write a query that returns the hire dates of all AdventureWorks<strong>2008</strong> employees in MM/DD/YY<br />

format.<br />

2. Write separate queries using a JOIN, a subquery, and then an EXISTS, to list all Adventure-<br />

Works<strong>2008</strong> persons who have not placed an order.<br />

3. Show the most recent 5 orders that were purchased from account numbers that have spent more<br />

than $70,000 with AdventureWorks.<br />

214

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!