查询:
select id , 数A , 数B , 法则 , 
case
when 法则=1 then 结果=(数A+数B)/4
when 法则=2 then 结果=(数A-数B)/4
when 法则=3 then 结果=数A*数B/4
when 法则=4 then 结果=数A/数B/4
end as 结果
from 表

解决方案 »

  1.   

    更新:
    update 表 set 结果=a.结果 from 
    (
    select id , 数A , 数B , 法则 , 
    case
    when 法则=1 then 结果=(数A+数B)/4
    when 法则=2 then 结果=(数A-数B)/4
    when 法则=3 then 结果=数A*数B/4
    when 法则=4 then 结果=数A/数B/4
    end as 结果
    from 表
    ) a where 表.id=a.id
      

  2.   

    --改一下
    1.查询
    select id,数A,数B,法则, 
    case
    when 法则=1 then (数A+数B)/4
    when 法则=2 then (数A-数B)/4
    when 法则=3 then 数A*数B/4
    when 法则=4 then 数A/数B/4
    end as 结果
    from 表2.修改
    update 表set 结果=a.结果 from 
    (
    select id,数A,数B,法则, 
    case
    when 法则=1 then (数A+数B)/4
    when 法则=2 then (数A-数B)/4
    when 法则=3 then 数A*数B/4
    when 法则=4 then 数A/数B/4
    end as 结果
    from 表
    ) a where 表.id=a.id
      

  3.   

    不需要那么复杂把???update 表set 结果=
      case
        when 法则=1 then (数A+数B)/4
        when 法则=2 then (数A-数B)/4
        when 法则=3 then 数A*数B/4
        when 法则=4 then 数A/数B/4
      end我觉得这样就可以了
      

  4.   

    请问在
    case
        when 法则=1 then (数A+数B)/4then后面还可以嵌入case吗?
      

  5.   

    可以啊,下面求 @i,@j 哪个大
    declare @i int
    declare @j int
    set @i=33
    set @j=23
    select case when @i>@j then @i else 
                                  case when @j>@i then @j end
                                  end