找回密码
 注册账号

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

初学者课程:T3自学|T6自学|U8自学软件下载课件下载工具下载资料:通资料|U8资料|NC|培训|年结积分规则 | 使用常见问题Q&A
知识库:U8 | | NC | U9 | OA | 政务U8|U9|NCC|NC65|NC65客开|NCC客开新手必读 | 任务 | 快速增金币用友QQ群[微信群]
查看: 6267|回复: 7

[求助] T+触发器错误,求助

  [复制链接]
发表于 2015-7-26 18:26:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册账号

×
第一次写触发器,有些错误,不知道在哪,求大神给看看,在线急等,谢谢!
进货单审核后自动生成材料出库单

--采购进货单审核触发生成材料出库单,弃审时删除对应的材料出库单
CREATE  TRIGGER Add_Other_Out_Vouch1 ON ST_RDRecord
FOR UPDATE
AS
IF UPDATE(VoucherState)--审核状态
    begin tran
BEGIN
         DECLARE @Bln int --判断是否已经增加了材料出库单
         DECLARE  @MaxVouch  INT
--ST_RDRecord表变量声明

DECLARE @Systime char(19)   --系统时间
DECLARE @NewAutoID INT
DECLARE @PurchaseArrival_ID uniqueidentifier --进货单ID
DECLARE @RDRecord_ID uniqueidentifier  --出库单表头ID
DECLARE @ID nvarchar(30)   --ID号(进货单编码)
DECLARE @code nvarchar(30)   --单据编号
DECLARE @voucherstate uniqueidentifier  --审核状态
DECLARE @accountstate uniqueidentifier   --核算状态
DECLARE @AccountingPeriod int   --当前月
DECLARE @AccountingYear int   --当前年
DECLARE @idbusiType uniqueidentifier    --直接领料
DECLARE @idvoucherType uniqueidentifier  --材料出库单
DECLARE @idrdStyle uniqueidentifier    --材料出库
DECLARE @IdMarketingOrgan uniqueidentifier  
--ST_RDRecord_b表变量声明
  
DECLARE @b_code int   --行号
DECLARE @quantity decimal(28,14) --数量
DECLARE @price decimal(28,14)  --单价
DECLARE @amount decimal(28,14)  --金额
DECLARE @idrDRecordDTO uniqueidentifier --ST_RDRecord.id
DECLARE @idinventory uniqueidentifier --存货编码
DECLARE @idunit uniqueidentifier --单位
DECLARE @idwarehouse uniqueidentifier --库位
--ST_RDRecord赋值
SET @PurchaseArrival_ID =(SELECT ID FROM PU_PurchaseArrival)  --进货单ID
SET @Systime  =(SELECT getdate())
SET @ID   =(SELECT code from PU_PurchaseArrival)  --ID号(进货单编码)
SET @code  =(SELECT code=@ID)
SET @RDRecord_ID =(SELECT ID FROM ST_RDRecord WHERE code=@ID)
SET @voucherstate =(SELECT id from eap_EnumItem where Name='未审核')
SET @accountstate =(SELECT id from eap_EnumItem where Name='未核算')
SET @AccountingPeriod =(SELECT DATEPART(month, GETDATE()))
SET @AccountingYear =(SELECT DATEPART(year, GETDATE()))
SET @idvoucherType =(SELECT id from SM_VoucherType where Name='材料出库单')
SET @idbusiType  =(SELECT id from AA_BusiType where Name='直接领料')
SET @idrdStyle  =(SELECT id from AA_RDStyle where Name='材料出库')
SET @IdMarketingOrgan =(SELECT id from AA_MarketingOrgan where disabled=0 )
END
--ST_RDRecord插入
--SET @Bln=(select count(*) from ST_RDRecord where code=@ID)
--IF ((@Bln<1)--如果不存在材料出库单,开始增加操作

--删除已有表单
DELETE FROM ST_RDRecord_b WHERE idrDRecordDTO=@RDRecord_ID
        DELETE FROM ST_RDRecord   WHERE ID=@RDRecord_ID

  begin
   insert into ST_RDRecord(ID,code,voucherstate,accountstate,AccountingPeriod,AccountingYear,idvoucherType,idbusiType,idrdStyle,IdMarketingOrgan,printtime,amount,RdDirectionFlagm,IsCostAccount,IsMergedFlow,IsAutoGenerate,VoucherDate,IsCarriedForwardOut,IsCarriedForwardIn,IsModifiedCode,SequenceNumber,VoucherDate,madedate,CreatedTime,updated,maker,updatedby,VoucherYear,VoucherPeriod)values(NewID(),@code,@voucherstate,@accountstate,@AccountingPeriod,@AccountingYear,@idvoucherType,@idbusiType,@idrdStyle,@IdMarketingOrgan,0,0,0,0,0,0,0,0,0,0,@Systime,@Systime,@Systime,@Systime,'demo','demo',@AccountingYear,@AccountingPeriod)
  SET @idrDRecordDTO=(select id from PU_PurchaseArrival where code=@code)
  DECLARE PU_PurchaseArrival_b_Cursor  CURSOR
  FOR
  SELECT code,quantity,OrigDiscountPrice,OrigTaxAmount,idinventory,idunit,idwarehouse FROM PU_PurchaseArrival_b WHERE idpurchaseArrivalDTO=@PurchaseArrival_ID
  SET @MaxVouch=0
  OPEN PU_PurchaseArrival_b_Cursor
  FETCH NEXT FROM PU_PurchaseArrival_b_Cursor
                INTO @b_code,@quantity,@price,@amount,@idinventory,@idunit,@idwarehouse

   WHILE @@FETCH_STATUS = 0
                           BEGIN
                               set @NewAutoID=@NewAutoID+1
  insert into ST_RDRecord_b(id,code,quantity,BaseQuantity,price,BasePrice,amount,ismanualcost,IsCostAccounted,taxflag,createdtime,sequencenumber,updated,updatedby,idrDRecordDTO,idinventory,idunit,idbaseUnit,idwarehouse,IsPromotionPresent,ispresent) values (NewID(),@b_code,@quantity,@quantity,@amount,0,0,0,0,@Systime,0,@Systime,'demo',@RDRecord_ID,@idinventory,@idunit,@idunit,@idwarehouse,0,0)
  set @MaxVouch=@MaxVouch+1
  FETCH NEXT FROM PU_PurchaseArrival_b_Cursor
                INTO @b_code,@quantity,@price,@amount,@idinventory,@idunit,@idwarehouse

  CLOSE PU_PurchaseArrival_b_Cursor
        DEALLOCATE PU_PurchaseArrival_b_Cursor
END
END
ElSE
BEGIN
DELETE FROM ST_RDRecord_b WHERE idrDRecordDTO=@RDRecord_ID
    DELETE FROM ST_RDRecord   WHERE ID=@RDRecord_ID
    END
    commit tran
END
 楼主| 发表于 2015-7-27 21:58:18 | 显示全部楼层
没人来帮一下吗??
回复 点赞 拍砖

使用道具 举报

发表于 2015-7-28 16:32:50 | 显示全部楼层
SET @ID   =(SELECT code from PU_PurchaseArrival) ,@ID这个值是多个
回复 点赞 拍砖

使用道具 举报

发表于 2016-1-28 09:00:37 | 显示全部楼层
有点模糊,。。。。
回复 点赞 拍砖

使用道具 举报

发表于 2016-4-13 08:43:44 | 显示全部楼层
set 那一段应该是不对
回复 点赞 拍砖

使用道具 举报

发表于 2016-4-22 08:36:30 | 显示全部楼层
学习学习,提升能力
回复 点赞 拍砖

使用道具 举报

发表于 2016-6-3 12:05:26 | 显示全部楼层
44444444444
回复 点赞 拍砖

使用道具 举报

发表于 2016-12-1 21:56:34 | 显示全部楼层
路过学习
回复 点赞 拍砖

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|站长微信|Archiver|手机版|小黑屋|用友之家 ( 蜀ICP备07505338号|51072502110008 )

GMT+8, 2024-6-2 16:23 , Processed in 0.038240 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表