dindanbukuna删除不完全重复的记录.sql 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. Declare @OrdersPerson varchar(max)
  2. select @OrdersPerson= isnull(@OrdersPerson,'')+''''+ cast(t3.temps as nvarchar(4000))+''','
  3. from (select * from
  4. (select count(t.temps) as counts,temps
  5. from (select *,(
  6. case id when null then '' else id end
  7. +case [money] when null then '' else [money] end
  8. + case ren when null then '' else ren end
  9. + case [date] when null then '' else [date] end
  10. + case bz when null then '' else bz end
  11. + case kind when null then '' else kind end
  12. + case ren2 when null then '' else ren2 end
  13. + case item when null then '' else item end
  14. + case paytype when null then '' else paytype end
  15. + case jdd when null then '' else jdd end
  16. )as temps
  17. from dindanbukuan) as t group by t.temps)as t2
  18. where counts>=2) as t3
  19. if substring(@OrdersPerson,len(@OrdersPerson),1) = ','
  20. begin
  21. set @OrdersPerson = left(@OrdersPerson,len(@OrdersPerson) - 1)
  22. end
  23. set @OrdersPerson ='
  24. Declare @tempStr varchar(max);
  25. select @tempStr= isnull(@tempStr,'''')+''''''''+ cast(tb2.autoid as nvarchar(4000))+'''''',''
  26. from (select autoid from (select * from
  27. (
  28. select *,(
  29. case id when null then '''' else id end
  30. +case [money] when null then '''' else [money] end
  31. + case ren when null then '''' else ren end
  32. + case [date] when null then '''' else [date] end
  33. + case bz when null then '''' else bz end
  34. + case kind when null then '''' else kind end
  35. + case ren2 when null then '''' else ren2 end
  36. + case item when null then '''' else item end
  37. + case paytype when null then '''' else paytype end
  38. + case jdd when null then '''' else jdd end
  39. )as temps
  40. from dindanbukuan
  41. ) as tt
  42. where temps in('+@OrdersPerson+') ) as tb where time is null) as tb2
  43. if substring(@tempStr,len(@tempStr),1) = '',''
  44. begin
  45. set @tempStr = left(@tempStr,len(@tempStr) - 1)
  46. end
  47. select @tempStr
  48. --set @tempStr=''select * from dindanbukuan where autoid in(''+@tempStr+'')''
  49. set @tempStr=''delete dindanbukuan where autoid in(''+@tempStr+'')''
  50. exec(@tempStr)
  51. '
  52. exec(@OrdersPerson)