create PROCEDURE EHR_PRO_SampleChkRuKu @recordid nvarchar(30), @banner int,--1审核,-1取消审核 @aprer nvarchar(20), @aprdate nvarchar(50) AS --过滤重复审核 declare @recordstate nvarchar(50) --是否审核 select @recordstate=recordstate from ehr_wah_Sampleinout where recordid=@recordid and recordtypeid='InUnit'--入库 if (@recordstate='Aproved' and @banner=1 ) or (@recordstate='UnAproved' and @banner=-1 ) return declare @depotcode nvarchar(50) declare @batchno nvarchar(50) declare @SampleID nvarchar(50) declare @remain nvarchar(50) declare mycursor1 cursor for select depotcode ,batchno ,SampleID ,remain from ehr_wah_Sampleinoutdtl where recordid=@recordid open mycursor1 fetch next from mycursor1 into @depotcode,@batchno,@SampleID,@remain while @@fetch_status=0 begin if not Exists(select * from ehr_wah_Samplestock where SampleID=@SampleID and batchno=@batchno and remain=@remain) begin insert into ehr_wah_Samplestock(SampleID,batchno ,remain ) select @SampleID,@batchno ,@remain end fetch next from mycursor1 into @depotcode,@batchno,@SampleID,@remain end close mycursor1 deallocate mycursor1