Not sure if this can be done using only sql, but I would rather ask by adding another step to the process.
so let's say for example i have a set of fictitious orders
+----------+-------------+----------+----------+-----------------+-----+
| Supplier | Destination | Req_Time | Prd_Code | Prd_Description | Qty |
+----------+-------------+----------+----------+-----------------+-----+
| A | B | 01:00 | 1 | Chair | 100 |
| A | B | 01:00 | 2 | Desk | 50 |
| A | B | 01:00 | 3 | Phone | 20 |
| A | B | 05:00 | 1 | Chair | 200 |
| A | B | 05:00 | 2 | Desk | 20 |
+----------+-------------+----------+----------+-----------------+-----+
And the current inventory list
+----------+----------+----------+-------+
| Supplier | Prd_Code | Prd_Desc | Stock |
+----------+----------+----------+-------+
| A | 1 | Chair | 150 |
| A | 2 | Desk | 40 |
| A | 3 | Phone | 100 |
+----------+----------+----------+-------+
there is a way that I can create a stored procedure (SQL 2008 -Compatible) that can subtract what I have in stock and leave me what I need
+----------+-------------+----------+----------+-----------------+-----+
| Supplier | Destination | Req_Time | Prd_Code | Prd_Description | Qty |
+----------+-------------+----------+----------+-----------------+-----+
| A | B | 01:00 | 2 | Desk | 10 |
| A | B | 05:00 | 1 | Chair | 150 |
| A | B | 05:00 | 2 | Desk | 20 |
+----------+-------------+----------+----------+-----------------+-----+
I would like to show you what I tried, but in this case I do not know where to start.
PS I have to thank this site for formatting tables for me it is very easy
https://ozh.imtqy.com/ascii-tables/
Will appreciate any understanding and any other examples: D