set @thggxh=isnull(@myggxh,"")
 set @thgydw=isnull(@mygydw,"")
 set @thjldw=isnull(@myjldw,"")
改为
set @thggxh=isnull(@myggxh,'')
 set @thgydw=isnull(@mygydw,'')
 set @thjldw=isnull(@myjldw,'')
别的都行,也能update

解决方案 »

  1.   

    EXISTS(select  *  from clsj where cllb=@myclmc and clmc=@myclmc and  ggxh=@thggxh and gydw=@thgydw and jldw=@thjldw)你这句话是不是想判断出记录是否存在,你的where 条件为什么构造的这么复杂,你的表没有主键吗?我认为问题出在where 条件上。
      

  2.   

    数据库是其他人设计的,我没有办法更改,数据库的设计人员设计的主键就是
    where从句的5个字段。我也相信是这个从句的问题,因为如果我输入的5个不为空的变量的话,update从句可以执行到,现在就是修改这个判断的问题
      

  3.   

    用rtime去掉字段后面的空格:
    CREATE PROCEDURE doupcl
    @mycllb varchar(50),
    @myclmc varchar(50),
    @myggxh varchar(50),
    @mygydw varchar(50),
    @myjldw varchar(50),
    @myupdate datetime,
    @myje  money
    AS
     declare @mycount int
     declare @SqlString nvarchar(1000)
     declare @thggxh varchar(50)
     declare @thgydw varchar(50)
     declare @thjldw varchar(50)
     set @thggxh=isnull(@myggxh,"")
     set @thgydw=isnull(@mygydw,"")
     set @thjldw=isnull(@myjldw,"")
     set @mycount=0
      
      if EXISTS(select  *  from clsj where rtime(cllb)=@myclmc and rtime(clmc)=@myclmc and  rtime(ggxh)=@thggxh and rtime(gydw)=@thgydw and rtime(jldw)=@thjldw)  begin
         update clsj
          set je = @myje,upyeardate=@myupdate
          where cllb=@myclmc and clmc=@myclmc and  ggxh=@thggxh and gydw=@thgydw and jldw=@thjldw
      end
      else begin
          insert into clsj(cllb,clmc,ggxh,gydw,jldw,je,upyeardate)
            values(@mycllb,@myclmc,@thggxh,@thgydw,@thjldw,@myje,@myupdate)
      end
    GO
      

  4.   

    写错!
     rtrim不好意思!
      

  5.   

    就是说你已经把源文件导入一个表中了,应该两句可完成,大体是这样,你调整一下:
    update A
          set je = B.je,upyeardate=@myupdate 
    from clsj A,源表 B
          where A.cllb=B.cllb and A.clmc=B.clmc and  A.ggxh=B.thggxh and A.gydw=B.thgydw and A.jldw=B.thjldw insert into clsj(cllb,clmc,ggxh,gydw,jldw,je,upyeardate)
     select cllb,clmc,ggxh,gydw,jldw,je,@myupdate from 源表 B
    where not exists (select 1 from clsj where cllb=B.cllb and clmc=B.clmc and  ggxh=B.thggxh and gydw=B.thgydw and jldw=B.thjldw)
      

  6.   

    请你比较详细地说明:
    什么情况下update语句能够执行到;
    什么情况下update语句无法执行到。
    这样才比较好找出原因。pengdali(大力),如果楼主的数据库使用默认配置,有没有rtrim()应该都是一样的。
      

  7.   

    谢谢各位的答复,去掉空格?不成功!
      主要是这样的,如果cllb='电子材料';clmc='集成电路',ggxh='74L301',
    gydw=Null,jldw=Null,update='2002-11-11',je=2时
    在这些条件下,第一次执行insert,这是对得,数据库中没有这条记录,可是
    当我将上面的条件只改je=20时,存储报错说:不能插入相同的记录?
      

  8.   

    检索没有对参数输入NULL值作判断。
    将检索条件改为
    EXISTS(select  *  from clsj where ((cllb=@mycllbor ISNULL(@mycllb,'')='') and (clmc=@myclmc or ISNULL(@myclmc,'')='') and  (ggxh=@thggxh or ISNULL(@thggxh ,'')='') and (gydw=@thgydw or ISNULL(@thgydw ,'')='') and (jldw=@thjldw or ISNULL(@thjldw ,'')='')) 
    如果不产生歧义,你可以将输入参数默认值设为''
    这样检索条件中就可以不使用ISNULL函数了。
      

  9.   

    第一次执行insert,这是对得,数据库中没有这条记录这时候你查看一下数据库,看看gydw、jldw字段是null还是''
      

  10.   

    插入后,gydw与jldw字段都是'',不再是null,我想也不应该是Null因为数据库设计他们不能为空。
    接受了zxdragon(zxdragon)的答案,分分,请zxdragon(zxdragon)到
    http://expert.csdn.net/Expert/topic/1232/1232364.xml?temp=.5257379登记一下,100分全归你了。
    学到一点,存储的参数最好有个默认值