clear markdown compare help donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 460376 distinct fiddles created so far.

CREATE TABLE 門市安全量基本檔 ([商品貨號] int, [安全量] int,門市編號 varchar(20)) ; CREATE TABLE 商品基本檔 ([商品貨號] int,基本撥量 int, [大類編號] int,淘汰 varchar(20) ) ; INSERT INTO 門市安全量基本檔 ([商品貨號], [安全量],[門市編號]) VALUES (11092, 48,'1001'), (1103, 36,'1001'), (15584, 16,'1001') ; INSERT INTO 商品基本檔 ([商品貨號],基本撥量, [大類編號],淘汰) VALUES (11092,4, 1,'1'), (1103,3, 1,'1'), (15584,3, 1,'1') ; select * into #temp_table from ( SELECT a.商品貨號 取代商品貨號,a.安全量,b.基本撥量 , case when (a.安全量/2) % b.基本撥量 = 0 then a.安全量/2 else b.基本撥量 * ((a.安全量/2)/b.基本撥量+1) end [新安全量] FROM 門市安全量基本檔 AS a RIGHT JOIN 商品基本檔 AS b ON b.商品貨號=a.商品貨號 WHERE (b.大類編號 BETWEEN '1' AND '7') AND a.門市編號='1001' AND b.淘汰='1' ) T update 門市安全量基本檔 set 安全量 = (select [新安全量] from #temp_table where 商品貨號 = 取代商品貨號) where 商品貨號 in (select 取代商品貨號 from #temp_table ); select * from 門市安全量基本檔;
商品貨號 安全量 門市編號
11092 24 1001
1103 18 1001
15584 9 1001
 hidden batch(es)