有一个表有1000多条记录,结构如下:
table: x,y,z
存储过程要实现,z=y/x/2(其中如果x=0,那么z=0;如果x>0,那么z=y/x/2)

解决方案 »

  1.   

    create proc jj
    as
     update tb set z=0 where x=0
     update tb set z=(y+0.0)/x/2 where x<>0
    go
      

  2.   

    create proc update_tb
    as
    begin 
    uppdate tablename
    set z=(case   when x=0 then 0
          when x>0 then y/x/2
           end
           ) end
      

  3.   

    use [数据库名]
    if exists (select name from sysobjects
    where name='count'and type='p')
    drop procedure count
    go
    use [数据库名]
    go
    CREATE procedure count
    update table set z=0 where x=0
    update table set z=x/y/2 where x>0
    go
      

  4.   

    create proc update_tb
    as
    begin 
    uppdate tablename
    set z=(case   when x=0 then 0
          when x>0 then y/x/2
                    else z
           end
           ) end
      

  5.   

    1、用游标遍历,一条一条的处理。
    2、update两次。
      

  6.   

    这么简单啊,已经对了!!
    为什么不用游标遍历,一条一条的处理。连循环都不用加SQL自动遍历记录了????