Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could select each calculation as a subquery (or more readably as a common table expression), and then base the next calculation on the subquery or previous CTE.</p> <p>The other option, which might be easier is just do all your calculations as multiple update statements, one after the other.</p> <p>Here's an example of the CTEs in turn...</p> <pre><code>;WITH c1 AS ( SELECT [Part Num], Daily, [O.F], [Order], MCT, Transit, [Safety], [Container Size], [No. of Kanban Card], [Run Line], [Lot Size], [Max. Inventory], [Trigger 1], [Trigger 2], [Trigger 3], [Avg. Inventory] FROM SuperMarketTest ), c2 AS ( SELECT [Part Num], Daily, [O.F], (Daily * [O.F]) AS [Order], MCT, Transit, [Safety], [Container Size], (Daily * ([O.F] + MCT + Transit + [Safety]) / [Container Size]) AS [No. of Kanban Card], [Run Line], [Lot Size], [Max. Inventory], [Trigger 1], [Trigger 2], [Trigger 3], [Avg. Inventory] FROM c1 ) , c3 AS ( SELECT [Part Num], Daily, [O.F], [Order], MCT, Transit, [Safety], [Container Size], [No. of Kanban Card], ([O.F] * Daily / [Container Size]) AS [Run Line], [Lot Size], ([No. of Kanban Card] * [Container Size]) AS [Max. Inventory] [Trigger 1], [Trigger 2], [Trigger 3], [Avg. Inventory] FROM c2 ) SELECT [Part Num], Daily, [O.F], [Order], MCT, Transit, [Safety], [Container Size], [No. of Kanban Card], [Run Line], [Lot Size], [Max. Inventory] (([No. of Kanban Card] - [Run Line]) * [Container Size]) AS [Trigger 1], (([No. of Kanban Card] - [Run Line] - 1) * [Container Size]) AS [Trigger 2], (([No. of Kanban Card] - [Run Line] - 2) * [Container Size]) AS [Trigger 3], (Daily * (0.5 * ([O.F] + MCT) + Transit + [Safety])) AS [Avg. Inventory] FROM c3 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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