|You’re the new DBA for a small sales organization who recently offered customers the opportunity to purchase products online. The sales director has requested to see the number of orders placed online by the month and year before the midmorning traffic meeting. It’s now your responsibility to provide him with this information as soon as possible.|
For our example we will be using just two columns from the Sales.SalesOrderHeader table in the AdventureWorks2012 database. You can download the AdventureWorks2012 database by clicking here.
|Given the above information we know we’ll be using the COUNT function. Let’s put together a simple query which should pull the information.
The basic query above will pull the below results set. However, giving these results to the Sales Director would likely put him in a bad mood and lessen his opinion of our T-SQL skills.
Now, let’s optimize our query a bit to make the Sales Director our new best friend.
Now that’s more like it!
We can now copy and paste this into Excel and wait for a nice thank you email or a follow up request.