Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am assuming that TableB has some relation to TableA</p> <p>This will not be possible if there is no way to relate between them.</p> <pre><code>DECLARE @tableA TABLE(Products VARCHAR(50), Actual_Qty INT, WIP_Qty INT) DECLARE @tableB TABLE(Products VARCHAR(50), Min_Qty INT, Max_Qty INT, Topup_Qty INT, Signal INT) INSERT INTO @tableA VALUES ('Product A',5, 0), ('Product B', 5, 0), ('Product C', 733 , 72), ('Product D', 532 , 90), ('Product E', 510 , 360) INSERT INTO @tableB VALUES ('Product A',100, 1000,995, 4), ('Product B',329, 857 ,852, 4), ('Product C',393, 1025,220, NULL), ('Product D',262, 683 ,61 , NULL), ('Product E',319, 832 ,680, 4) SELECT A.Products,A.Actual_Qty,A.WIP_Qty,A.Actual_Qty-A.WIP_Qty Topup,'&gt;' [ ],B.Products,B.Min_Qty,B.Max_Qty,B.Topup_Qty,B.Signal, 'now calculate &gt; ' [ ] , CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty SignalTest , CASE WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty &gt;= 60 THEN 1 WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty BETWEEN 50 AND 60 THEN 2 WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty BETWEEN 30 AND 50 THEN 3 WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty &lt; 30 THEN 4 END Signal FROM @tableA A INNER JOIN @tableB B ON B.Products = A.Products /*Here is the update but, you can switch the tables for your tables*/ UPDATE B SET B.Signal = (SELECT CASE WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty &gt;= 60 THEN 1 WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty BETWEEN 50 AND 60 THEN 2 WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty BETWEEN 30 AND 50 THEN 3 WHEN CONVERT(MONEY,(A.Actual_Qty-A.WIP_Qty )*100)/B.Max_Qty &lt; 30 THEN 4 END Signal) FROM @tableA A INNER JOIN @tableB B ON B.Products = A.Products SELECT * FROM @tableB </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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