日期:2014-05-18  浏览次数:20431 次

如何存儲過程實現日報進銷存!(高手請進,,感恩!!)
create   table   #Temp_Stock
(Dt_op   Datetime,
  Id_wc   int,
  Beg_Qty   decimal(16,4),
  In_Qty     decimal(16,4),
  Out_Qty   decimal(16,4),
  Scr_Qty   decimal(16,4),
  End_Qty   decimal(16,4)
)
每日回報各id_wc的In_Qty,Out_Qty,Scr_Qty數據!
期末值:end_Qty=beg_QTy+In_Qty+Out_Qty-Scr_Qty
存儲過程實現各id_wc 期初,進,銷,期末。
查詢時,昨日期末=今日期初
---請幫忙指示方法!!!

------解决方案--------------------
给点原绐数据
------解决方案--------------------
----参考:
select
T2.Id_wc,T2.dt_op,(T1.In_qty-T1.Out_qty-T1.Scr_Qty) AS Beg_Qty,
T2.In_qty,T2.Out_qty,T2.Scr_Qty,(T1.In_qty-T1.Out_qty-T1.Scr_Qty) +
T2.In_qty-T2.Out_qty-T2.Scr_Qty AS End_QTY
fom #temp_Stock T2
join
(
select id_wc,dt_op,Beg_Qty,In_Qty,Out_Qty,Scr_Qty
from #temp_Stock
)T1
ON CONVERT(varchar, T2.T2.dt_op, 120 )T1.T2.dt_op = CONVERT(varchar, T1.T2.dt_op-1, 120 )

------解决方案--------------------
--上面手误
----参考:
select
T2.Id_wc,T2.dt_op,(T1.In_qty-T1.Out_qty-T1.Scr_Qty) AS Beg_Qty,
T2.In_qty,T2.Out_qty,T2.Scr_Qty,(T1.In_qty-T1.Out_qty-T1.Scr_Qty) +
T2.In_qty-T2.Out_qty-T2.Scr_Qty AS End_QTY
fom #temp_Stock T2
join
(
select id_wc,dt_op,Beg_Qty,In_Qty,Out_Qty,Scr_Qty
from #temp_Stock
)T1
ON CONVERT(varchar, T2.dt_op, 120 )= CONVERT(varchar, T1.dt_op-1, 120 )