123456789101112131415161718192021222324252627282930313233343536373839 |
- use ddf_jg
- declare @id int;
- declare @order nvarchar(50);
- declare @count int;
- declare @maxcount int;
- declare @OKCount int;
- declare @status nvarchar(10);
- with subtbl
- as
- (
- select id, count(*) as cot from dindansp where spid is not null and spid <> '' group by id
- )select id as [order],cot into
- select identity(int,1,1) as id, * into
- select @maxcount = count(id) from
- while @maxcount > 0
- begin
-
- select @order = [order], @count = cot from
-
- select @OKCount = count(status2) from dindansp where id = @order and status2 = 'OK' and spid is not null and spid <> ''
-
- select @status = status3 from dindan where id = @order
- if (@status <> 'OK' and @count = @OKCount)
- begin
- update dindan set status3 = 'OK' where id = @order
- print '更新订单' + @order
- print @count
- print @maxcount
- print @OKCount
- end
- set @maxcount = @maxcount -1
- end
- drop table
- drop table
|