Sei sulla pagina 1di 12

BASIS DATA 2

TUGAS UAS PRAKTEK


Dosen : Bapak Karsito S.Kom

Makalah Stored Procedure dan Function

“Kehadiran Mahasiswa”

Sella Monica
311 510 225
TI. 15. D7
STT PELITA BANGSA
2017
TUGAS UAS
PRAKTEK BASIS DATA 2
MAKALAH KEHADIRAN MAHASISWA

Disusun oleh :

NIM : 311 510 225

Nama : Sella Monica

SEKOLAH TINGGI TEKNOLOGI PELITA BANGSA

TEKNIK INFORMATIKA

2017
1. Membuat database dan table Mahasiswa, Absensi, Kehadiran, Nilai

--membuat database--
create Database Kehadiran_Mahasiswa
use Kehadiran_Mahasiswa

--membuat tabel mahasiswa--


create table Mahasiswa(
NIM varchar (9),
Nama varchar (20),
Kelas varchar (10),
Alamat varchar (20),
Id int)
select *from Mahasiswa

--membuat tabel kehadiran--


create table Kehadiran(
Id int,
Date_in date,
NIM varchar (9),
Status varchar (10))
select *from Kehadiran

--membuat tabel absensi--


create table Absensi(
Id int,
NIM varchar (9),
Mechine_Id varchar (2),
Date_in datetime)
select *from Absensi

--membuat tabel nilai--


alter table Nilai (
NIM varchar (9),
UTS int (5),
UAS int (5),
Tugas int (5),
Kehadiran int (10),
Nilai_akhir int (5),
Nilai_huruf varchar (5))
select *from Nilai
select *from Mahasiswa
select *from Absensi
select *from Kehadiran
select *from Nilai

Tampilan table yang sudah dibuat

2
2. SP Status Kehadiran Mahasiswa

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Sella Monica>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE Status_Kehadiran
@Tgl date
AS
BEGIN
SET NOCOUNT ON;
declare @NIM varchar (9),
@Cursor_sts as cursor
set @Cursor_sts = cursor for select NIM from Absensi where
convert (date, Date_in)=@tgl;
open @Cursor_sts
fetch next from @Cursor_sts into @NIM
while (@@FETCH_STATUS=0)
Begin
update Kehadiran set Status = 'Hadir' where Date_in=@tgl and
NIM=@NIM;
fetch next from @Cursor_sts into @tgl
End
Close @Cursor_sts
Deallocate @Cursor_sts

END
GO
3. SP-Kehadiran mahasiswa

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Sella Monica>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
alter PROCEDURE Kehadiran_Mhs
@Tgl date
AS
BEGIN
SET NOCOUNT ON;
declare @NIM varchar (9),
@Cursor_Mahasiswa as cursor

set @Cursor_Mhs = cursor for select NIM from Mahasiswa


open @Cursor_Mhs
fetch next from @Cursor_Mhs into @NIM
while (@@FETCH_STATUS=0)
Begin
insert into Kehadiran (Date_in,NIM) values (@Tgl,@NIM);
fetch next from @Cursor_Mhs into @NIM
End
Close @Cursor_Mhs
Deallocate @Cursor_Mhs
END
GO
3. Function Kehadiran

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: < Sella Monica >
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE FUNCTION F_mhs
(
@TglAw date,
@TglAk date,
@NIM varchar (9)

)
RETURNS smallint
AS
BEGIN
declare @jm smallint;

RETURN (select count (NIM)from Kehadiran where Date_in between @TglAw


and @TglAk and NIM=@NIM and status ='Hadir');

END
GO
4. Store Prosedure Nilai

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================

-- Author: < Sella Monica>


-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
create PROCEDURE Nilai
@TglAw date,
@TglAk date
AS
BEGIN
SET NOCOUNT ON;
declare @NIM varchar (9),
@UTS smallint,
@UAS smallint,
@Tugas smallint,
@Hadir smallint,
@Tot_nilai smallint,
@Nilai_angka char,
@curor_nilai as cursor
set @cursor_nilai = cursor for select NIM, UTS, UAS, Tugas, dbo.F_mhs
(@TglAw, @TglAk, Nilai. NIM) as Kehadiran from Nilai;
open @cursor_nilai
fetch next @cursor_nilai into @NIM, @UTS, @UAS, @Tugas, @Hadir
while (@@FETCH_STATUS=0)
BEGIN
SET @Tot_nilai=(0.3 * @UTS)+(0.4 * @UAS)+(0.15 * @Tugas) + (0.15 *
Hadir);
if (@Tot_nilai >=85 and @Tot_nilai <=100)
begin
set @Nilai_angka= 'A';
end
else if (@Tot_nilai >=75 and @Tot_nilai <=84)
begin
set @Nilai_angka= 'B';
end
else if (@Tot_nilai >=65 and @Tot_nilai <=74)
begin
set @Nilai_angka='C';
end
else if (@Tot_nilai >=55 and @Tot_nilai <=64)
begin
set @Nilai_angka='D';
end
else
begin
set @Nilai_angka= 'E';
end
update Nilai set Kehadiran = @Hadir, Nilai_Angka=@Tot_nilai, Nilai_huruf
fetch next from @cursor_nilai into @NIM, @UTS, @UAS, @Tugas, @Hadir
end
close @cursor_nilai
deallocate @cursor_nilai
END
GO
5. Tampilan GUI kehadiran mahasiswa

1. Mahasiswa
2. Absensi

3, Kehadiran
4, Nilai

Potrebbero piacerti anche