数据库语句如下
if (select reply from consult )is not null update consult set condition = '已回答'  else update consult set condition='未回答' 
问题:当reply有值,不为空时, condition为 已回答,,如果reply为空时, condition为未回答。花絮:我在语句中都加入where id ='固定值',语句就通的,我想批量操作,该如何处理?都大神啊

解决方案 »

  1.   

    (select reply from consult 这个选择肯定会有数据啊,你是不是得加个条件啊,否则肯定都会是  未回答
      

  2.   

    那我想全选怎么写?id全选批量处理啊。或者reply全选。。我要把每一行数据都处理了
      

  3.   

     update consult set condition = '已回答'  where  reply is not null   
      

  4.   

    最笨的方法 。一个条件写一个sql!select xxx from xxx  
    update xxxxxxxxxxxxxxxxxxxxxxx
    select xxx from xxx  
    update xxxxxxxxxxxxxxxxxxxxxxx
      

  5.   


    写个循环SQL语句在SQL执行一下
      

  6.   

    if  Exists(select reply from consult ) 
    begin
    update consult set condition = '已回答'
    end
      else 
    begin
    update consult set condition='未回答'
    end这样写
      

  7.   

    楼主是打算用这一条语句来分情况更新condition字段吧?可是你的2条update语句都是更新全表的
      

  8.   

    看来只能这样了update consult set condition = '未回答'
    update consult set condition = '已回答' where  reply is not null 分2部写,先覆盖掉
      

  9.   


    你要分两部分写的话,第一句也加上where,能少刷几条记录
      

  10.   

    写个函数应该可以的,更新的时候以reply 作为参数调用函数
      

  11.   

    这样写:
    update consult set condition =(case when reply =null then '未回答' else '已回答'  end)
    测试通过
      

  12.   

    纠正下:
    update consult set condition =(case when reply is null then '未回答' else '已回答' end)