码迷,mamicode.com
首页 > 其他好文 > 详细

表单触发器

时间:2014-12-26 16:55:38      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:

控制表体不能有重复行

 

ALTER TRIGGER [dbo].[seoutstock_Update] ON [dbo].[SEOutStock]
FOR insert,update
AS
DECLARE @FInterID  int
DECLARE @FStatus    int
DECLARE @count      int

If UPDATE(FStatus)
BEGIN
SELECT @FInterID = FInterID
    FROM INSERTED
    
      select @count = count(*) 
          from 
               (select FItemID 
                from seoutstockEntry 
                where FInterID = @FInterID and FItemID in (select FItemID from t_ICItem where FBatchManager=0)
                group by FItemID  
                having count(*)>1) as temp
          if @count >0 
   begin
    ROLLBACK TRAN
             RAISERROR(‘单身有物料重复行!‘,16,1)
   end

END

 

控制单据二级审核 反审

ALTER TRIGGER [dbo].[ICStockBill_update1]
            ON [dbo].[ICStockBill]
FOR update
AS

 SET NOCOUNT ON

 if exists (select 1 from  deleted  where  ftrantype =41 and FHeadSelfD0132=35360 and isnull(fcheckerid,0)<>0) 
 begin
     if exists (select 1 from  inserted  where  ftrantype =41 and FHeadSelfD0132=35360 and isnull(fcheckerid,0)=0)
     begin

              DECLARE @FStatus   int
                    DECLARE @Finterid   int
  
               select @FStatus=fcheckerid,@Finterid=finterid from icstockbill
               where finterid in (select finterid from inserted) 
                     if isnull(@FStatus,0)=0
                     begin
               ROLLBACK TRAN 
                    RAISERROR(‘已经出库,无法反审单据,请冲红!‘,18,18)
                     end   
        end
 end


表单触发器

标签:

原文地址:http://my.oschina.net/u/2297484/blog/360701

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!