删除已知订单号的重复订单.sql 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. --删除完全重复的dindan表记录,已知订单号的情况下;
  2. use db
  3. declare @order nvarchar(50)
  4. declare @autoid int
  5. declare @count int
  6. set @order = '订单号'
  7. select @count = count(*) from dindan where id = @order
  8. if (@count > 0 )
  9. begin
  10. --将指定的订单号记录插入到dindan_cc表里;
  11. select identity(int,1,1) as atid,* into dindan_cc from dindan where id = @order
  12. --删除dindan表里的订单;
  13. delete from dindan where id = @order
  14. select @autoid = min(atid) from dindan_cc
  15. --重装取回一条记录插入到dindan表中;
  16. insert into dindan select [id]
  17. ,[money1]
  18. ,[money2]
  19. ,[money3]
  20. ,[name1]
  21. ,[name2]
  22. ,[taoxiid]
  23. ,[taoxiname]
  24. ,[taoxijiage]
  25. ,[taoxizs]
  26. ,[time1]
  27. ,[time2]
  28. ,[time3]
  29. ,[bm]
  30. ,[ren]
  31. ,[discount]
  32. ,[payed1]
  33. ,[payed2]
  34. ,[payed3]
  35. ,[payed4]
  36. ,[payed5]
  37. ,[time4]
  38. ,[time5]
  39. ,[takezs]
  40. ,[choosezs]
  41. ,[status]
  42. ,[clothescount2]
  43. ,[outside2]
  44. ,[style]
  45. ,[payed3time]
  46. ,[payed4ren]
  47. ,[payed4time]
  48. ,[status2]
  49. ,[status3]
  50. ,[waiter1]
  51. ,[waiter2]
  52. ,[waiter3]
  53. ,[waiter4]
  54. ,[bz]
  55. ,[taketime]
  56. ,[clothescount]
  57. ,[outside]
  58. ,[bz2]
  59. ,[bz3]
  60. ,[urgent]
  61. ,[status4]
  62. ,[status5]
  63. ,[waiter5]
  64. ,[waiter6]
  65. ,[pinyin1]
  66. ,[pinyin2]
  67. ,[waiter7]
  68. ,[status6]
  69. ,[phone1]
  70. ,[phone2]
  71. ,[status7]
  72. ,[memberno]
  73. ,[waiter8]
  74. ,[time6]
  75. ,[status8]
  76. ,[bruncount]
  77. ,[tichenren1]
  78. ,[tichenren2]
  79. ,[tichenren3]
  80. ,[tichenren4]
  81. ,[tichenren5]
  82. ,[send1]
  83. ,[send2]
  84. ,[send3]
  85. ,[datetime4]
  86. ,[datetime5]
  87. ,[datetime6]
  88. ,[waiter12]
  89. ,[waiter22]
  90. ,[waiter1rate]
  91. ,[waiter2rate]
  92. ,[waiter13]
  93. ,[waiter14]
  94. ,[waiter23]
  95. ,[waiter24]
  96. ,[waiter12rate]
  97. ,[waiter13rate]
  98. ,[waiter14rate]
  99. ,[waiter22rate]
  100. ,[waiter23rate]
  101. ,[waiter24rate]
  102. ,[ren2]
  103. ,[renrate]
  104. ,[ren2rate]
  105. ,[txtype]
  106. ,[delphotos]
  107. ,[growthtxselname]
  108. ,[delphotos2]
  109. ,[designno]
  110. ,[designreplaceno]
  111. ,[size]
  112. ,[dindantype]
  113. ,[contractno1]
  114. ,[contractno2]
  115. ,[cfno]
  116. ,[calldate]
  117. ,[from]
  118. ,[reason]
  119. ,[time7]
  120. ,[time8]
  121. ,[time9]
  122. ,[time10]
  123. ,[authorize]
  124. ,[discount2]
  125. ,[authorize2]
  126. ,[bz4]
  127. ,[satisfaction1]
  128. ,[satisfaction2]
  129. ,[satisfaction3]
  130. ,[satisfaction4]
  131. ,[satisfaction5]
  132. ,[satisfaction6]
  133. ,[satisfaction7]
  134. ,[bz5]
  135. ,[send4]
  136. ,[send5]
  137. ,[waiter9]
  138. ,[curno]
  139. ,[xplrr]
  140. ,[xplrtime]
  141. ,[satisfaction8]
  142. ,[VisitPeople1]
  143. ,[VisitPeople2]
  144. ,[VisitPeople3]
  145. ,[VisitPeople4]
  146. ,[VisitPeople5]
  147. ,[VisitPeople6]
  148. ,[VisitPeople7]
  149. ,[VisitPeople8]
  150. ,[VisitTime1]
  151. ,[VisitTime2]
  152. ,[VisitTime3]
  153. ,[VisitTime4]
  154. ,[VisitTime5]
  155. ,[VisitTime6]
  156. ,[VisitTime7]
  157. ,[VisitTime8] from dindan_cc where atid = @autoid
  158. --删除临时表;
  159. drop table dindan_cc
  160. end