| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 
 |  
declare @ref_cadre integer
declare @old_chef integer
declare @new_chef integer
 
declare curs cursor 
for select GC.refCadre,GC.refChef,ccc.chef
from global_chefs GC
inner join COUPLES_CADRE_CHEF ccc on  ccc.cadre = GC.RefCadre 
 and ccc.chef <> GC.RefChef
 and manual = 0
 where DateFin is null
 
open curs
fetch next from curs into @ref_cadre, @old_chef,@new_chef
 
while(@@FETCH_STATUS = 0)
BEGIN
/*On cloture l'ancien couple*/
update global_chefs set dateFin=GETDATE(), Manual=0 where refCadre=@ref_cadre and refChef=@old_chef and dateFin is null
/*On crée le nouveau*/
insert into global_chefs(RefCadre,RefChef,DateDebut,DateFin, Manual)
values (@ref_Cadre,@new_chef,GETDATE(),null,0)
 
 fetch next from curs into @ref_cadre, @old_chef,@new_chef
END
 
close curs
deallocate curs | 
Partager