USE [erpdb1]
GO
/****** Object:  StoredProcedure [dbo].[sp_checkdingdan]    Script Date: 12/29/2014 15:38:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_checkdingdan] @docid varchar(30),@ertext varchar(100) output
AS
DECLARE  @input_id varchar(20)
DECLARE  @row_count int
BEGIN 
    DECLARE cur_input CURSOR  FOR
   select inputid from cpmb_detail where biaodanid = (select chanpinmingchen from dingdanzhu where biaodanid= @docid) and xz='t'
   group by inputid order by inputid  
 set @input_id =0 
 set @row_count = 0 
 --/*
 set @ertext ='y' 
 OPEN cur_input
 
    FETCH  cur_input INTO @input_id
 WHILE @@FETCH_STATUS = 0
      BEGIN
         set @row_count = 0
         SELECT @row_count = count(*) from dingdanfu d,dingdanzhu a where  a.biaodanid  =@docid AND  a.biaodanid = d.biaodanid
    and xuhao in (select xuhao from cpmb_detail where inputid =@input_id and a.chanpinmingchen= cpmb_detail.biaodanid);
         if @row_count = 0
         BEGIN        
            set @ertext ='生产单录入无效,产品位置为:' +@input_id+ '的物料必须选择一项,请重新录入!'
            delete dingdanzhu where biaodanid = @docid;
            CLOSE cur_input
               DEALLOCATE cur_input
            return
         END  
   FETCH  cur_input INTO @input_id
      END
    CLOSE cur_input
    DEALLOCATE cur_input 
    --*/
END