马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你看出了作者的深度?深处半米!当初是冲那么多的大牛给他写序才买的,后来才发现无啥内容,作者也只是才用几年的新手,百花了几十两银子,再次感叹当今社会的虚伪与浮躁存储历程
--|///
----//
--(@@)
--┏━━━━━━━━━oOOo-(_)-oOOo━┓
--┃界说于2004-07-16┃
--┃本钱试算存储历程界说,盘算本钱┃
--┃Oooo┃
--┗━━━━━━━━━oooO━-()━┛
--())/
--((_/
--\_)
CREATEPROCEDUREsp_costing_compute
(@out_matnrvarchar(18),
@out_werksvarchar(4),
@out_datetimedatetime)
AS
--拔出赠品
declare@matnrvarchar(18),@werksvarchar(4),@kriqidatetime,@meinsvarchar(10)
declare@bomatnrvarchar(18),@bomsehlvarchar(10),@mengefloat
declare@pricefloat,@danwvarchar(20)
declare@umrezfloat,@aapricefloat,@jjpricefloat,@aratefloat,@jratefloat,@asyfloat,@jsyfloat
declare@cpjgfloat,@umrenfloat
set@cpjg=0
--盘算产制品本钱代价
Declaremycursorcursorforselectmeins,aprice,jpricefromtb_matnrwhereconvert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)andmatnr=@out_matnrandplant=@out_werks
openmycursor
fetchmycursorinto@meins,@aaprice,@jjprice
closemycursor
deallocatemycursor
declarebccursorcursorforselectbomatnr,bomsehl,mengefromtb_bomwherecpmatnr=@out_matnrandwerks=@out_werksandconvert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
openbccursor
fetchbccursorinto@bomatnr,@bomsehl,@menge
while@@fetch_status=0
begin
declarejgcursorcursorforselectprice,meinsfromtb_bcjgwherematnr=@bomatnrandplant=@out_werksandconvert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
openjgcursor
fetchjgcursorinto@price,@danw
closejgcursor
deallocatejgcursor
if@price=0
begin
updatetb_matnrsetmstatus=置疑wherematnr=@out_matnrandplant=@out_werksandconvert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
break
end
--假如代价单元和bom单元分歧,必要举行转换
if@bomsehl@danw
begin
declarezhgxcursorcursorforselectumrezfromtb_switchwherematnr=@bomatnrandmsehl=@danw
openzhgxcursor
fetchzhgxcursorinto@umrez
closezhgxcursor
deallocatezhgxcursor
end
if@umrezisnull
set@umrez=1
set@cpjg=@cpjg+@menge*@price/@umrez
fetchnextfrombccursorinto@bomatnr,@bomsehl,@menge
end
closebccursor
deallocatebccursor
--检察bom制品单元与制品发卖单元,假如分歧增加转换干系
declarecpzhcursorcursorforselectumrenfromtb_switchwherematnr=@out_matnrandmsehl=@meins
opencpzhcursor
fetchcpzhcursorinto@umren
closecpzhcursor
deallocatecpzhcursor
if@umrenisnull
set@umren=1
if@cpjg0
set@cpjg=@cpjg/@umren
ifnot@aapriceisnull
begin
set@arate=@aaprice-@cpjg
if@aaprice0
set@asy=@arate/@aaprice
end
else
begin
set@arate=0
set@asy=0
end
ifnot@jjpriceisnull
begin
set@jrate=@jjprice-@cpjg
if@jjprice0
set@jsy=@jrate/@jjprice
end
else
begin
set@jrate=0
set@jsy=0
end
updatetb_matnrsetcbprice=@cpjg,apeyoff=@arate,jpayoff=@jrate,arate=@asy,jrate=@jsywherematnr=@out_matnrandplant=@out_werksandconvert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
GO
线上或者测试环境经常出现的误操作总是让DBA同学那么闹心。 |