--有错误提示没有?
表A中的某些insert不进去

解决方案 »

  1.   

    ALTER procedure [dbo].[A]          
     @gzid   char(20),          
     @djlxbs char(3)          
    as                
     declare           
       @djbh     char(14),          
       @jxlx     char(1),          
       @djlx     char(3),          
       @rq       char(10),          
       @bm       char(20),          
       @ywy      char(20),          
       @username char(20),          
       @jzhh     char(11),          
       @zhy      char(30),          
       @spid     char(11),          
       @hw       char(11),          
       @spkc     decimal(14,2),          
       @spje     decimal(14,2),          
       @hwkc     decimal(14,2),          
       @hwje     decimal(14,2),          
       @maxbh    char(11),          
       @zhaiyao  char(16),          
       @tmp_zoo  decimal(14,2),          
       @bendian  char(3)          
               
       set @djbh=''          
       set @bm=''          
       set @ywy=''          
       set @zhy=''          
       set @rq=''          
       set @spid='***'          
       set @hw='***'          
       set @spkc=0          
       set @spje=0          
       set @hwkc=0          
       set @hwje=0          
       set @tmp_zoo=0          
       set @bendian=''          
      

  2.   

    select @djbh=left(fieldvalue,14)           
            from tmp_dj_mast (nolock)           
            where gzid=@gzid and fieldname='djbh'          
               
     set @jxlx=left(@djbh,1)          
     set @djlx=left(@djbh,3)          
               
     select @bm=left(fieldvalue,20)           
            from tmp_dj_mast (nolock)          
            where gzid=@gzid and fieldname='bm'          
     select @ywy=left(fieldvalue,20)           
            from tmp_dj_mast (nolock)          
            where gzid=@gzid and fieldname='ywy'          
     select @username=left(fieldvalue,20)          
            from tmp_dj_mast (nolock)           
            where gzid=@gzid and fieldname='username'          
     select @zhy=left(fieldvalue,30)           
            from tmp_dj_mast (nolock)          
            where gzid=@gzid and fieldname='zhy'          
     select @rq=left(fieldvalue,10)           
            from tmp_dj_mast (nolock)          
            where gzid=@gzid and fieldname='rq'          
     select @bendian=left(fieldvalue,3)           
            from tmp_dj_mast (nolock)          
            where gzid=@gzid and fieldname='bendian'          
               
               
     declare @errcode integer          
     set @errcode=500   /* 移库出入库单据存储*/                    
               
     declare @return integer          
     set @return=0          
              
              
     --启动事务          
     declare @tran_point int          
      set @tran_point=@@trancount          
               
     if @tran_point=0          
       begin tran tran_dbykcrk          
     else          
       save tran tran_dbykcrk          
              
               
     exec @return=SOF_getmaxbh 'JZH',2,@jzhh OUTPUT          
       if @return>0           
       begin          
         set @return = 20          
         goto err_lab          
       end           
               
     select dchw,drhw,spid,shl,chbdj,dbdj,isnull(dbje,0) as dbje,isnull(ml,0) as ml,isnull(pihao,'') as pihao,          
            isnull(xgdjbh,'') as xgdjbh,isnull(baozhiqi,'') as baozhiqi,isnull(miejph,'') as miejph,isnull(sxrq,'') as sxrq,isnull(recnum,0) as recnum          
         into #t_djmx          
         from tmp_dj_CDB314 (nolock)          
         where gzid=@gzid          
     IF @@ERROR<>0 --select into #t_djmx失败          
       BEGIN          
         SET @return=34          
         GOTO err_lab          
       END          
              
     if not exists(select 1 from #t_djmx)          
      begin           --从tmp_dj_CDB314提取基础数据失败          
       set @return=1          
       goto err_lab          
      end           
               
     --2004-11-16 zhaoxm  对不允许产生负库存的货位进行拦截。          
     if (@djlxbs='314')          
     begin          
       if exists(          
        select c.spid,c.dchw,c.pihao,sum(shl) as shl          
        from         
        (          
          select a.spid,a.dchw,a.pihao,-a.shl as shl           
          from #t_djmx a          
          union          
          select b.spid,b.hw as dchw,b.pihao,isnull(b.shl,0) as shl           
          from #t_djmx a,sphwph b           
       where a.spid=b.spid and a.dchw=b.hw and a.pihao=b.pihao          
        ) c ,huoweizl d          
        where c.dchw=d.hw and d.isljfkc='是'           
        group by c.spid,c.dchw,c.pihao           
        having sum(c.shl)<0)          
       --2007-04-03  zlb 修正:负库存拦截不起作用,注释多余的语句if @@error <> 0          
       -- if @@error <> 0           
       begin              --对不允许产生负库存的货位进行拦截          
      set @return=25          
      goto err_lab          
       end           
     end          
      

  3.   

    --------------------------------------------------------------------------
    select distinct a.dchw,a.pihao,a.spid,a.baozhiqi,a.miejph,a.sxrq,a.chbdj as gebjj,isnull(b.spid,'***') as spid1          
              into #t_hwsppcc           
              from #t_djmx a,sphwph b (nolock)          
              where a.dchw*=b.hw and a.spid*=b.spid and a.pihao*=b.pihao          
       if @@error <> 0           
         begin         --登记表#t_hwsppcc失败          
           set @return=28          
           goto err_lab          
         end           
       --declare @dengjrq varchar(19)    
         --  set @dengjrq=convert(varchar(19),getdate(),20)    
    insert into sphwph(hw,spid,pihao,baozhiqi,miejph,sxrq,gebjj)           
              select dchw,spid,pihao,baozhiqi,miejph,sxrq,gebjj       
              from #t_hwsppcc          
              where spid1='***'          
       if @@error <> 0           
         begin         --登记表sphwph失败          
           set @return=29          
           goto err_lab          
         end           
       drop table #t_hwsppcc          
      

  4.   

    先去判断有无相同记录,如有那么就UPDATE,接着再去判断没有的记录然后INSERT进去
      

  5.   

    会不会跟MSSQL某些机制有关,请大虾指点