'Parfait' 'Inparfait': Avg Avg

You might also like

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 3

CC 2008

create proc parf


@n int
as
begin
declare @i int
declare @som int
set @i=1
set @som=0
while @i<@n
begin
if @n%@i=0
begin
set @som=@som+@i
set @i=@i+1
end
else set @i=@i+1
end
if @som=@n print('parfait')
else print('inparfait')
end

create proc createtab


as
begin
create table note(cod_etud nchar(10) constraint pk_cod primary key
references etudiant,
anne int,notcc1 float,notcc2 float,
cod_mat nchar(10) constraint fk_cod foreign key references Matiere)
end

create proc moyenne


@cod nchar(10)
as
declare @nbr float
begin
SELECT (avg(notcc1)+avg(notcc2))/2,anne
from note
where cod_etud=@cod
group by anne
end

alter table Etudiant


add nbr_cc int

create proc edit


as
begin
declare @n int
declare @cod nchar(10)
declare m cursor for
select count(*),cod_etud
from note
group by cod_etud
open m
fetch next from m into @n,@cod
while(@@FETCH_STATUS=0)
begin
update Etudiant
set nbr_cc=@n
where cod_etud=@cod
fetch next from m into @n,@cod
end
close m
deallocate m
end

create proc calc


as
begin
declare @my(moyenne) float
declare @ap (t)varchar
declare @cod (cod_etd)nchar(10)
declare @an(anne) int
declare @cd(cod_mat) nchar(10)
declare m cursor for
select cod_etud,(notcc1+notcc2)/2,cod_mat,anne
from note
group by cod_mat,anne,cod_etud
open m
fetch next from m into @cod,@my,@cd,@an
while(@@FETCH_STATUS=0)
begin
if @my<7
set @ap='nv'
else if @my>=7 and @my<10
set @ap='rat'
else set @ap='v'
update note
set app=@ap
where cod_etud=@cod and anne=@an and cod_mat=@cd
update note
set moyenne=@my
where cod_etud=@cod and anne=@an and cod_mat=@cd
fetch next from m into @cod,@my,@cd,@an
end
close m
deallocate m
end
create trigger ty on note
for insert
as
declare @my float
declare @ap varchar
declare @cod nchar(10)
declare @an int
declare @cd nchar(10)
select @my=(notcc1+notcc2)/2,@cod=cod_etud,@an=anne,@cd=cod_mat
from inserted
if @my<7
set @ap='nv'
else if @my>=7 and @my<10
set @ap='rat'
else set @ap='v'
update note
set app=@ap
where cod_etud=@cod and anne=@an and cod_mat=@cd
update note
set moyenne=@my
where cod_etud=@cod and anne=@an and cod_mat=@cd
update Etudiant
set nbr_cc=nbr_cc+1
where cod_etud=@cod

create trigger trig on Etudiant


for insert
as
declare @d date
declare @cod nchar(10)
declare @nbr int
select @d=date_nais_etud,@cod=cod_etud
from inserted
set @nbr=LEN(@d)
if @nbr=10
begin
select convert(char(10),@d,103)
select replace(@d,'Q',0)
select replace(@d,'O',0)
select convert(DATE,@d,103)
select QUOTENAME(@d)
update Etudiant
set date_nais_etud=@d
where cod_etud=@cod AND DAY(@d) between 1 and 31
and month(@d) between 1 and 12
and YEAR(@d) between 1753 AND 9999
end
else print('erreur')

You might also like