Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.83 KB | None | 0 0
  1. declare @support_id_parcours bigint --Variable de parcours pour les support_id
  2. declare @support_id_table table (support_id bigint) --Table pour le parcour des support_id
  3. declare @delete_vehicle_support_id_to_delete table (id bigint) --Table des delete à faire
  4. declare @delete_contributor_support_id_to_delete table (id bigint) --Table des delete à faire
  5.  
  6. --Selection des vehicule_support à supprimer-------------------------------------
  7. insert into @support_id_table
  8. select support_id
  9. from vehicle_support
  10. group by support_id, vehicle_id
  11. having count(support_id)>1
  12.  
  13. while (select count(*) from @support_id_table) >0
  14.     begin
  15.     set @support_id_parcours = (select top 1 support_id from @support_id_table)
  16.     delete from @support_id_table where support_id = @support_id_parcours
  17.     insert into @delete_vehicle_support_id_to_delete select MIN(id) from vehicle_support where support_id=@support_id_parcours
  18. end
  19.  
  20. --Selection des vehicule_support à supprimer--------------------------------------
  21. insert into @support_id_table
  22. select support_id
  23. from contributor_support
  24. group by support_id, contributor_id
  25. having count(support_id)>1
  26.  
  27. while (select count(*) from @support_id_table) >0
  28.     begin
  29.     set @support_id_parcours = (select top 1 support_id from @support_id_table)
  30.     delete from @support_id_table where support_id = @support_id_parcours
  31.     insert into @delete_contributor_support_id_to_delete select MIN(id) from vehicle_support where support_id=@support_id_parcours -- A la place de ce selecte le DELETE SA MAMAN
  32. end
  33.  
  34. --Suppression des doublons
  35. select * from @delete_vehicle_support_id_to_delete
  36. select * from @delete_contributor_support_id_to_delete
  37. --delete from vehicle_support where id in (select id from @delete_vehicle_support_id_to_delete)
  38. --delete from contributor_support where id in (select id from @delete_contributor_support_id_to_delete)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement