IT tutorials
 
Database
 

SQL Server : Constraints and Rock Solid Inventory Systems (part 4) - Adding rows out of date order

1/19/2013 5:10:09 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Adding rows out of date order

At the moment, our inventory system robustly handles the insertion of new rows to the end of the inventory (i.e. in date order). However, far more complex is the situation where we need to insert a row when it is not the last in the trail history. It requires two actions:

  • inserting the row itself

  • modifying CurrentQuantity and PreviousQuantity for all the later rows in the history trail for the item.

Both inserting and updating need to be done in a single command, so we need to use MERGE. The MERGE which gets the job done is quite complex and is shown in Listing 22.

Listing 22. Inserting a row in the middle of a history trail.

This code handles inserting rows before the first date, inbetween dates, and after the last date. More importantly, it will also handle the case when there is already a row with the same ItemID and ChangeDate, automatically modifying that row (and all "later" rows for the same item) to reflect the new net change, which is computed as the old change plus the new change. Finally, it will also automatically delete a row if the new net change equals zero (no change).

As we have seen, modifying anywhere other than in the very end of a history trail may be quite involved, but the integrity of our data is never compromised. In many cases, such as inventory systems, this complexity of modifications in the middle of a history is perfectly acceptable, because under normal circumstances we just never need to do it. However, this approach is not for everyone; we need to decide whether to use it on a case-by-case basis.

 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us