国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

前段時(shí)間寫的一個(gè)關(guān)于成本計(jì)算的存儲過程!

2024-07-21 02:07:21
字體:
供稿:網(wǎng)友

--                              ///|///
--                             //  - -  //
--                             (  @ @  )
--┏━━━━━━━━━oooo-(_)-oooo━┓
--┃   定義于2004-07-16                                  ┃
--┃  成本試算存儲過程定義,計(jì)算成本  ┃
--┃                                                  oooo   ┃
--┗━━━━━━━━━ oooo━-(   )━┛
--                                           (   )   ) /
--                                            / (   (_/
--                                             /_)
create procedure sp_costing_compute
    ( @out_matnr varchar(18),
     @out_werks varchar(4),
     @out_datetime datetime)
as
--插入贈品
declare @matnr varchar(18),@werks varchar(4),@kriqi datetime,@meins varchar(10)
declare @bomatnr varchar(18),@bomsehl varchar(10),@menge float
declare @price float,@danw varchar(20)
declare @umrez float,@aaprice float,@jjprice float,@arate float,@jrate float,@asy float,@jsy float
declare @cpjg float,@umren float
set @cpjg = 0
--計(jì)算產(chǎn)成品成本價(jià)格
declare mycursor cursor for select meins,aprice,jprice from tb_matnr where convert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)  and matnr = @out_matnr and [email protected]_werks
open mycursor
fetch mycursor into @meins,@aaprice,@jjprice
close mycursor
deallocate mycursor
declare  bccursor cursor for select bomatnr,bomsehl,menge from tb_bom where [email protected]_matnr and [email protected]_werks and convert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
open bccursor
fetch bccursor into @bomatnr,@bomsehl,@menge
   while @@fetch_status = 0
   begin
       declare jgcursor cursor for select price,meins from tb_bcjg where [email protected] and [email protected]_werks and convert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
       open jgcursor
       fetch jgcursor into @price,@danw
       close jgcursor
       deallocate jgcursor
                   if @price = 0
                               begin
                                       update tb_matnr set mstatus='置疑' where matnr = @out_matnr and plant = @out_werks and convert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
                                       break
                               end
--如果價(jià)格單位和bom單位不同,需要進(jìn)行轉(zhuǎn)換
       if @bomsehl <> @danw
              begin
                   declare zhgxcursor cursor for select umrez from tb_switch where matnr = @bomatnr and msehl = @danw
                   open zhgxcursor
                   fetch zhgxcursor into @umrez
                   close zhgxcursor
                   deallocate zhgxcursor                 
              end    
      if @umrez is null
                 set @umrez = 1
      set @cpjg = @cpjg + @menge * @price / @umrez                     
     fetch next from bccursor into @bomatnr,@bomsehl,@menge
   end  
   close bccursor
   deallocate bccursor
--查看bom成品單位與成品銷售單位,如果不同添加轉(zhuǎn)換關(guān)系
     declare cpzhcursor cursor for select umren from tb_switch  where matnr = @out_matnr and msehl = @meins
     open cpzhcursor
     fetch cpzhcursor into @umren
     close cpzhcursor
     deallocate cpzhcursor
     if @umren is null
                 set @umren = 1
     if @cpjg <> 0
                 set @cpjg = @cpjg / @umren
  if not @aaprice is null      
          begin
             set @arate = @aaprice - @cpjg
             if @aaprice <> 0
                 set @[email protected] / @aaprice
          end
     else
          begin
               set @arate=0
               set @asy=0
          end
     if not @jjprice is null
           begin
              set @jrate = @jjprice - @cpjg
              if @jjprice <> 0
                  set @jsy = @jrate / @jjprice
           end
     else
          begin
             set  @jrate = 0
             set  @jsy = 0
          end  

   update tb_matnr set cbprice = @cpjg,[email protected],[email protected],[email protected],[email protected] where [email protected]_matnr and [email protected]_werks and convert(varchar(10),kriqi,120)=convert(varchar(10),@out_datetime,120)
go

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 朝阳县| 遂溪县| 淅川县| 三台县| 海伦市| 梅州市| 金塔县| 广西| 石景山区| 和平区| 桂平市| 漯河市| 东乌珠穆沁旗| 孝昌县| 巢湖市| 陇川县| 乌审旗| 汉阴县| 子长县| 依兰县| 含山县| 海盐县| 滁州市| 金门县| 鄂尔多斯市| 潜江市| 虹口区| 柯坪县| 开平市| 桂阳县| 通州市| 宁陕县| 汉寿县| 荃湾区| 广昌县| 宜章县| 尚志市| 玉田县| 德钦县| 合肥市| 盐边县|