IQC跳撿 T-SQL

轉載請註明出處,聯繫我: [email protected]
本人熱衷於數據庫技術及算法的研究,志同道合之士, 歡迎探討

ALTER proc [dbo].[proc_CheckIfNeedIQC]
@VendorID nvarchar(50),
@PartNum nvarchar(50),
@company nvarchar(20)
as
    declare @n int;
	set @n=0;
    select @n=count(*) from RcvDtl t1
    left join erp.Vendor t2 on t1.vendornum=t2.vendornum and t1.company=t2.company
    where t1.InspectedDate is not null and t2.VendorID=@VendorID and t1.PartNum=@PartNum;
if (@n=0)
begin
	select 1 CheckLabel;
end
else
begin   
    SELECT t2.VendorID,t1.InspectedDate,t1.PartNum,t1.NeedCheck_c,t1.LotNum 
	into #CheckList
	FROM RcvDtl t1
    left join erp.Vendor t2 on t1.vendornum=t2.vendornum and t1.company=t2.company
    where t1.InspectedDate is not null and t2.VendorID=@VendorID and t1.PartNum=@PartNum
    order by t1.LotNum ;
	--select * from #CheckList;
	declare @i nvarchar(40);
	declare @j int;
	declare @m int;
	declare @q int;--跳了多少次
	set @j=0;
	set @m=0;
	set @q=0;
	select @i=max(LotNum) from #CheckList where NeedCheck_c=1
	select @j=count(*) from #CheckList where LotNum<=@i;
	select @m=count(*) from #CheckList;
	set @q=@m-@j
	declare @r int;
	set @r=-1;
	select @r=InspectionFrequency from [check] where SupplierNumber=@VendorID and ShippingNumber=@PartNum and company=@company;
	--print cast(@r as nvarchar)+' '+cast(@q as nvarchar)
  if(@r>0)
	begin
	if(@r-@q<=0)
	begin
	   select 1 CheckLabel;
	end
	else if(@r-@q>0)
	begin
	   select 0 CheckLabel;
	end
  end
  else if(@r=-1)
  begin
     select 1 CheckLabel;
  end
end
GO
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章