update a set a.fprovince=(case a.fprovince when '' then isnull(b.fprovince,' ') end) from tb_cl a,tb_kh b where a.fkhh=b.fkhh因为表tb_cl中province默认是not null,而tb_kh中默认是null,所以在update时假如tb_kh中有空值的province,出现下面的提示:服务器: 消息 515,级别 16,状态 2,行 1
无法将 NULL 值插入列 'fprovince',表 'svw.dbo.tb_cl';该列不允许空值。UPDATE 失败。
语句已终止。但是在语句中我已经用isnull来判断了,没有直接给它赋值。
而这样用却可以:
update a set a.fprovince=isnull(b.fprovince,' ') from tb_cl a,tb_kh b where a.fkhh=b.fkhh请高手帮忙指点下上面那句错在哪里???

解决方案 »

  1.   

    update a set a.fprovince=(case a.fprovince when '' then isnull(b.fprovince,' ') 
    else a.fprovince
    end) from tb_cl a,tb_kh b where a.fkhh=b.fkhh
      

  2.   

    or:update a 
    set a.fprovince=isnull(b.fprovince,' ')
    from tb_cl a,tb_kh b 
    where a.fkhh=b.fkhh
    and a.fprovince=''
      

  3.   

    (case a.fprovince when '' then isnull(b.fprovince,' ') end)======
    (case a.fprovince when '' then isnull(b.fprovince,' ') else null end)所以当a.fprovince <> ''的时候,你的语句就试图更新为null
      

  4.   

    谢谢Yang_(扬帆破浪),已经解决!