CREATE TABLE #temp ( qty INT , qty1 INT , qty2 INT ); INSERT INTO #temp ( qty, qty1, qty2 ) VALUES ( 7000, 0, 0 ), ( 6000, 0, 0 ), ( 5000, 0, 0 ), ( 4000, 0, 0 ); DECLARE @p INT = 15000; UPDATE #temp SET @p = @p - qty,qty1 = CASE WHEN @p>0 THEN qty WHEN qty+@p>0 THEN qty+@p ELSE 0 END,qty2=@p SELECT * FROM #temp; DROP TABLE #temp;
标签:temp,INT,WHEN,qty,qty1,qty2,计算,sql,递减 From: https://www.cnblogs.com/miaololi/p/17613640.html