一个存储过程实现增删改操作




-------------------------------------------------------------
--作者:Dezai
--时间:2008-5-28
-------------------------------------------------------------
--存储过程的功能:对表 UBS_CAS_PriceFormBatch 进行添加、更新、删除、获取操作。
-------------------------------------------------------------
--参数说明:
-------------------------------------------------------------
/*
@DataAction 添加更新删除的标志位
@ID  ID
@BatchNo  ('批次号')
@ItemClassID  分类
@PurchaserUID  分类
@AuditorUID  批准人
@CheckerUID  审核者
@PubDate  拟制时间
@CheckDate  审核时间
@PassDate  批准时间
@State  表单状态
@FormType  表单类型
@SupplierCode  供应商代码
@CompanyType  厂别
@InputModelMaterial  输入成本模型的物料
@Purchaser  
@Auditor  
@Checker  
@RejectReason  
*/    
Create PROCEDURE UBS_CAS_PriceFormBatchAction
    @DataAction int,
    @ID int = 0,
    @BatchNo varchar(50),
    @ItemClassID int,
    @PurchaserUID int,
    @AuditorUID int,
    @CheckerUID int,
    @PubDate datetime,
    @CheckDate datetime,
    @PassDate datetime,
    @State int,
    @FormType int,
    @SupplierCode varchar(50),
    @CompanyType int,
    @InputModelMaterial varchar(50),
    @Purchaser varchar(50),
    @Auditor varchar(50),
    @Checker varchar(50),
    @RejectReason varchar(500)
AS
begin   tran
   SET NOCOUNT ON

if @DataAction=0
begin
    
    insert into UBS_CAS_PriceFormBatch
    (
        [BatchNo],
        [ItemClassID],
        [PurchaserUID],
        [AuditorUID],
        [CheckerUID],
        [PubDate],
        [CheckDate],
        [PassDate],
        [State],
        [FormType],
        [SupplierCode],
        [CompanyType],
        [InputModelMaterial],
        [Purchaser],
        [Auditor],
        [Checker],
        [RejectReason]
    )
    values
    (
        @BatchNo,
        @ItemClassID,
        @PurchaserUID,
        @AuditorUID,
        @CheckerUID,
        @PubDate,
        @CheckDate,
        @PassDate,
        @State,
        @FormType,
        @SupplierCode,
        @CompanyType,
        @InputModelMaterial,
        @Purchaser,
        @Auditor,
        @Checker,
        @RejectReason
    )
    set
        @ID=scope_identity()
end
if @DataAction=1
begin
    Update [UBS_CAS_PriceFormBatch] SET
        [BatchNo] = @BatchNo,
        [ItemClassID] = @ItemClassID,
        [PurchaserUID] = @PurchaserUID,
        [AuditorUID] = @AuditorUID,
        [CheckerUID] = @CheckerUID,
        [PubDate] = @PubDate,
        [CheckDate] = @CheckDate,
        [PassDate] = @PassDate,
        [State] = @State,
        [FormType] = @FormType,
        [SupplierCode] = @SupplierCode,
        [CompanyType] = @CompanyType,
        [InputModelMaterial] = @InputModelMaterial,
        [Purchaser] = @Purchaser,
        [Auditor] = @Auditor,
        [Checker] = @Checker,
        [RejectReason] = @RejectReason
    Where
        
        [ID] = @ID
end
if @DataAction=2
begin
    delete from [UBS_CAS_PriceFormBatch] where  [ID] = @ID
end


if @DataAction=3
begin
select
    [BatchNo],
    [ItemClassID],
    [PurchaserUID],
    [AuditorUID],
    [CheckerUID],
    [PubDate],
    [CheckDate],
    [PassDate],
    [State],
    [FormType],
    [SupplierCode],
    [CompanyType],
    [InputModelMaterial],
    [Purchaser],
    [Auditor],
    [Checker],
    [RejectReason],
    from [UBS_CAS_PriceFormBatch]    
    where
        
        [ID] = @ID
        
        
        end
        
        
        if   @@error<>0   goto   sqlerr

commit   tran  
  return  
  sqlerr:  
      rollback  

    SET NOCOUNT OFF
GO



评论: 0 | 引用: 0 | 查看次数: 5234
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 30 字 | UBB代码 关闭 | [img]标签 关闭