dindansp只有入底和入册,但错误设置成dindan取件ok.sql 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. declare @id int;
  2. declare @order nvarchar(50);
  3. declare @count int;
  4. declare @maxcount int;
  5. declare @OKCount int;
  6. declare @status nvarchar(10);
  7. with subtbl
  8. as
  9. (
  10. select id, count(*) as cot from dindansp where spid is null or spid = '' group by id
  11. )select id as [order],cot into #tempall from subtbl
  12. --select * from #tempall
  13. --3.获取指定字段的不重复记录,过滤掉不完全重复的记录;
  14. select identity(int,1,1) as id, * into #tempresult from #tempall
  15. select @maxcount = count(id) from #tempresult
  16. while @maxcount > 0
  17. begin
  18. -- 获取指定自增列记录;
  19. select @order = [order], @count = cot from #tempresult where id = @maxcount
  20. -- 获取未ok的数量
  21. select @OKCount = count(status2) from dindansp where id = @order
  22. -- 获取订单取件状态;
  23. select @status = status3 from dindan where id = @order
  24. if (@status = 'OK' and @count = @OKCount)
  25. begin
  26. update dindan set status3 = '未取' where id = @order
  27. print '更新订单' + @order
  28. print @count
  29. print @maxcount
  30. print @OKCount
  31. end
  32. set @maxcount = @maxcount -1
  33. end
  34. drop table #tempall
  35. drop table #tempresult