2015-02-26 14:54:29藍宇星

累計金額運算

--累計金額運算

declare @cs_amt_70 int   --參數宣告
set @cs_amt_70 = (select s_amt_70 from #s_amt where cust = @cust)  --設定參數值

-- 計算當累計金額大於, 等於 @cs_amt_70設定的金額時, 回傳所查詢到的所有資料
select * from #d_amt
where rid <=            
 select top 1 rid  
 from #d_amt as a  
 where (select SUM(s_amt) from #d_amt where rid<=a.rid)>=@cs_amt_70
order by rid

上一篇:crusor for 迴圈