如题 title     body
2          4
2         空白
我想实现一个功能!选择当title相同时,自动选择有数据(不为空)的body ,然后将title相同的其他空白 body列数据 update掉!求写法,谢谢

解决方案 »

  1.   

    自己写一个存储过程,
    先获取body不为空的数据再updatebody为空的数据
      

  2.   

    将数据update成如下
    title    body
    2         4
    2         4
      

  3.   

    update tb set body=bd from (select max(body)bd,title from tb group by title)t where t.title=tb.title and isnull(tb.body,'')=''
      

  4.   

    选择相同的title有数据的body,你可以按body倒序排
    select * from 表 where title=2 order by body desc;更新就加个条件 where body is null
    update 表  set body = 某个值 where title=2 and isnull(body,'')=''
      

  5.   

    用having判断个数大于1的取出来  再判断等于空白就update
      

  6.   


    你要是将为空的body更新 与body不为空的记录 一样,则改成
    update 表 A set body = (select top 1 body from 表 where title=A.title order by body desc) where title=2 and isnull(body,'')=''
      

  7.   


    [code=sql]SELECT DISTICUT * (SELECT * FROM TABLE WHERE body NOT NULL)
    AS TEMP
    [/ code]
      

  8.   

    你说的那个 update 你要自己在细化下 如果出现下面的情况你就要自己吧条件说明了 
    title     body
    2          4
    2         \"\"
    2         新增
    2         [null]
    2         /s这种请款你要选择哪个作为更新源才能决定 符合 update 的写法。
      

  9.   

    问题解决了,大神们可以解释下 where title=2 and isnull(body,'')='' 这里    isnull是指的是title还是body啊   isnull(body,'')=''求说明啊,为什么这样写啊?
      

  10.   

     isnull(body,'')=''
    意思是如果body为null,先将null转成''
    等价于 body is null or body=''