1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| IF EXISTS (select codcl from inserted inner join client on client.codcl=inserted.codcl
and villecl='paris')
BEGIN
--On tente d'insérer dans la table achat un client de paris
--On regarde s'il en existe déjà un dans la table achat
IF NOT EXISTS (select cl.codcl from client cl inner join achat a on cl.codcl = a.codcl and cl.villecl = 'paris')
BEGIN
--Il n'en existe pas encore
insert into achat select * from inserted
END
ELSE
BEGIN
--Il en existe déjà un
print 'complet';
--Attention print ne renvoie pas d'erreur à mon avis il vaut mieux un rollback transaction ou autre ...
END
END
ELSE
BEGIN
--Les clients ne sont pas de paris
insert into achat select * from inserted
END |