Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed suggestions - SQL and ASP.NET
    text
    copied!<p>I have a problem I tried solving on my own, but didn't get far (tried different approaches but all of them ended up in a big wall of code, that eventually did not do what I needed). So I'm here asking for any advice, solution, code snippets you can offer. Thanks in advance!</p> <p>I have an SQL db with tables PARTS, ASSEMBLIES and FORMULA. As names suggest assemblies are made out of parts but can also be made out of other assemblies. How assemblies are made is written in table FORMULA. In my application I can enter how many assemblies have been made (increase stock). But when I increase stock for an assembly, I need to decrease stock for corresponding parts and (sub)assemblies. For better understanding I'll illustrate this with an example;</p> <p>PARTS</p> <pre><code>partID partStock p1 100 p2 100 p3 100 </code></pre> <p>ASSEMBLIES</p> <pre><code>assID assStock ass1 10 ass2 10 </code></pre> <p>FORMULA</p> <pre><code>assID parts isAssembly quantity ass1 p1 no 1 ass1 p2 no 2 ass1 ass2 yes 1 ass2 p3 no 2 </code></pre> <p>Explanation of the table: <code>ass1</code> is assembled from 1x <code>p1</code> + 2x <code>p2</code> + 1x <code>ass2</code> (which is another assembly) and <code>ass2</code> is assembled from 2x <code>p3</code></p> <p>So when I increase stock of ass1 for 10 (this is not a problem, I can do it), I would also need to decrease stock for p1(10), p2(20), ass2(10). And if stock for ass2 would be &lt;10, I'd need to decrease stock of p3(for a remaining number).</p> <p>Does anyone even understand what I want to do here? :D</p> <p>Any suggestions are welcome, thank you very much! Oh, and I'm writing my web app in C#. :)</p> <p>EDIT: As it has been pointed out in comments, I firstly search for an idea (design pattern) how to accomplish this. Actual SQL queries and coding is not such a big problem.. If anyone has some helpful code, its a bonus. ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload