大概如下: 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
大概如下: 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
怎么这么乱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
表kuan的Temcode加索引试试 create index idx_01 on kuan(Temcode)
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
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
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
create index idx_01 on kuan(Temcode)
结果是用了很多次的update,一次次手动更新反倒更快,寒一个