case when不知道行不行,详细.

解决方案 »

  1.   

    大概如下:
    begin tran
    declare cr cursor for select px, k,  s , g, n, x from #tt
    open cr
    fetch next from cr into @Px, @k, @S, @g ,@n , @x
    while @@fetch_Status = 0
    begin
       if @px = 1 
    begin
    update  kuan
              set  fs1 = @stone ,
            fs1    = @Guig,
      fs1 = @Num,
      fs1 = @xiangf
     where  Temcode = @kuanh
    end else
    if @px =2 
            begin
    update  kuan
              set  fs2e = @stone ,
            fs2    = @Guig,
      fs2 = @Num,
      fs2 = @xiangf
     where  Temcode = @kuanh
    end else 
            if @px =3
            .......  fetch next from cr into @Px, @kuanh, @Stone, @guig,@num , @xiangf
    end
    commit tran
    close cr
    deallocate cr
      

  2.   

    大概如下: 
    begin tran 
    declare cr cursor for select px, k,  s , g, n, x from #tt 
    open cr 
    fetch next from cr into @Px, @k, @S, @g ,@n , @x 
    while @@fetch_Status = 0 
    begin 
      if @px = 1 
    begin 
    update kuan 
          set fs1 = @stone , 
          fs1    = @Guig, 
    fs1 = @Num, 
    fs1 = @xiangf 
    where  Temcode = @kuanh 
    end else 
    if @px =2 
            begin 
    update kuan 
          set fs2e = @stone , 
          fs2    = @Guig, 
    fs2 = @Num, 
    fs2 = @xiangf 
    where  Temcode = @kuanh 
    end else 
            if @px =3 
            .......   fetch next from cr into @Px, @k, @S, @g ,@n , @x 
    end 
    commit tran 
    close cr 
    deallocate cr 
      

  3.   

    怎么这么乱begin tran
    declare cr cursor for select px, k,  s, g, n, x from #tt
    open cr
    fetch next from cr into @Px, @k, @S, @g ,@n , @x 
    while @@fetch_Status = 0
    begin
       if @px = 1 
    begin
    update  kuan
              set  fs1 = @stone ,
            fs1 = @Guig,
      fs1 = @Num,
      fs1 = @xiangf
     where  Temcode = @kuanh
    end else
    if @px =2 
    begin
    update  kuan
              set  fs2 = @stone ,
            fs2 = @Guig,
      fs2 = @Num,
      fs2 = @xiangf
     where  Temcode = @kuanh
    end else
    if @px =3 
            。  fetch next from cr into @Px, @k, @S, @g ,@n , @x 
    end
    commit tran
    close cr
    deallocate cr
      

  4.   

    表kuan的Temcode加索引试试
    create index idx_01 on kuan(Temcode)
      

  5.   

    是啊,游标不知怎么回事
    结果是用了很多次的update,一次次手动更新反倒更快,寒一个
      

  6.   

    可以用批量更新,为什么要用cursor啊