sqlserver 存储过程例子

该SQL存储过程用于处理批量条码验证。它首先声明并初始化变量,然后定义一个游标遍历输入的表格。对于每个条码,检查其在WMS_CP_Barcode_IM表中的状态,如果满足条件则更新条码状态并插入历史记录,否则将错误的条码添加到错误列表。最后,根据错误列表的长度返回结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/***
描述:
作者:
建立时间:
修改时间:
***/

CREATE proc xxxxx(  
 @doccode nvarchar(50),--凭证单号  
 @stcode nvarchar(50), --仓库编号  
 @userCode nvarchar(50),--操作人  
 @mytable [WMS_CP_11275] readonly, --扫描的托码表格  
 @Result nvarchar(200) output)  
as              
begin  
  
  declare @tp_Barcode nvarchar(50)  
  declare @tp_MatCode nvarchar(50)  
  declare @tp_WHCode nvarchar(50)  
  declare @tp_actBoxNums nvarchar(50)  
    
  declare @strErrorBarcodeList nvarchar(500)=''  
    
  DECLARE My_Cursor CURSOR --定义游标  
  FOR SELECT * FROM @mytable  --查出需要的集合放到游标中  
  OPEN My_Cursor --打开游标  
  fetch next from My_Cursor into @tp_Barcode,@tp_MatCode,@tp_WHCode,@tp_actBoxNums  
  WHILE @@FETCH_STATUS = 0  
    BEGIN  
        --在这里做一些逻辑处理  
        --再做一次数据的验证  
        if (exists(select * from WMS_CP_Barcode_IM with(nolock) where Barcode=@tp_Barcode and StCode=@stcode and DataState=2 ))  
   begin  
    --当满足验证条件时,则进行以下真正的逻辑处理  
    --1,先更新条码状态信息  
    update WMS_CP_Barcode_IM set StCode='',WHCode='',DataState=3 where Barcode=@tp_Barcode  
    --2,再插入条码扫描历史表  
    Insert into WMS_CP_IO_History(Barcode,ModeType,Form_Id,Doccode,Operator,OperationTime)  
    values(@tp_Barcode,'-','11-275',@doccode,@userCode,getdate())  
   end  
        else  
   --当验证不通过时,抛一个错误出去  
   set @strErrorBarcodeList=@strErrorBarcodeList + @tp_Barcode + ','  
          
        fetch next from My_Cursor into @tp_Barcode,@tp_MatCode,@tp_WHCode,@tp_actBoxNums  
    END  
  CLOSE My_Cursor --关闭游标  
  DEALLOCATE My_Cursor --释放游标  
  if (@strErrorBarcodeList<>'')  
 begin  
  set @Result=@strErrorBarcodeList  
 end  
  else   
 begin  
  set @Result='OK'  
 end  
end  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值