-
Notifications
You must be signed in to change notification settings - Fork 0
/
EvaluasiAntrian.sql
60 lines (49 loc) · 1.26 KB
/
EvaluasiAntrian.sql
1
2
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
create procedure EvaluasiAntrian
@idKegiatan int
as
declare @result table (
idTahapan int,
[Rata-rata Durasi (dalam menit)] int
)
declare @jamAwal time
declare @jamAkhir time
declare @selisihJam int = 0
declare @i int = 0
declare @jumlahTahap int = 0
declare @urutanTahapan varchar(6)
select @urutanTahapan = urutanTahapan
from Penyelenggara join KegiatanVaksinasi on Penyelenggara.IdPenyelenggara = KegiatanVaksinasi.IdPenyelenggara
where IdKegiatan = @idKegiatan
while @urutanTahapan != ''
begin
declare @currTahap int = cast((select left(@urutanTahapan, 1)) as int)
set @urutanTahapan = SUBSTRING(@urutanTahapan, 2, len(@urutanTahapan))
declare curs CURSOR FOR
select jamAwal, jamAkhir
from Mengikuti
where IdKegiatan = @idKegiatan and IdTahapan = @currTahap
open curs
fetch next from curs into @jamAwal, @jamAkhir
while @@FETCH_STATUS = 0
begin
set @selisihJam = @selisihJam + datediff(minute,@jamAwal,@jamAkhir)
set @i += 1
fetch next from curs into @jamAwal, @jamAkhir
end
close curs
deallocate curs
if @i != 0
begin
set @selisihJam /= @i
end
else
begin
set @selisihJam = 0
end
insert into @result
select @currTahap, @selisihJam
set @i = 0
end
select *
from @result
exec EvaluasiAntrian 1