Change the Status of Table Items

Downloads
95324.zip

Test your SQL Server savvy in this month's Reader Challenge. Submit your solution in an email message to challenge@ sqlmag.com by April 12. Umachandar Jayachandran, a SQL Server Magazine technical editor, will evaluate the responses. We'll announce the winner in an upcoming SQL Server Magazine UPDATE. (Make sure you're signed up for this free weekly email newsletter at http://www.sqlmag.com/email.) The first-place winner will receive $100, and the second-place winner will receive $50.

Problem:


Siva is a database developer for a company that sells products online. The company stores its product inventory and order-processing data in a SQL Server 2000 database. For the purpose of the problem, use the tables in Listing 1 for the order-processing data.

The Orders table contains the details of each customer's online order form. The OrderDetails table contains the line items for each order. The status of the order is tracked at both the order and order detail levels, although the status values are different from table to table. Listing 2 shows some sample data for the tables.

Orders are created with at least one line item in a single transaction. The status change for a particular order happens in the following sequence: Orders are initially created with a "Processing" status. Once all of the line items in an order have been processed, the status changes to "Shipped." If the order is cancelled, the status is set to "Cancelled." A batch processes the OrderDetails entries, then updates the status of each line item. At the end of the batch process, Siva wants to update the Orders table and mark all orders that have been completely processed.

Help Siva complete the following tasks:

  1. Write an UPDATE statement that can change the order status according to the status of the line items.
  2. Optimize the schema by adding any additional indexes to help with the processing of the UPDATE statement or queries that look at orders of a particular status.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.