Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DELETE topscore
- DECLARE
- @idj INT,
- @idje INT,
- @score INT,
- @titre VARCHAR(30),
- @scoremax INT,
- @idjeuxmax INT
- DELCARE curseur CURSOR FOR
- SELECT p.idJoueur,p.idJeux, score, titre FROM PARTIE p
- JOIN JEUX je ON p.idJeux=je.idJeux
- OPEN curseur
- FETCH NEXT FROM curseur INTO
- @idj,@idje,@score,@titre
- WHILE @@FETCH_STATUS = 0
- BEGIN
- IF NOT EXISTS (SELECT * FROM topscore t
- JOIN JEUX je ON t.idJeux=je.idJeux
- WHERE je.titre = @titre AND t.idJoueur=@idj)
- BEGIN
- PRINT 'Insert score : ' + CONVERT(VARCHAR,@score)
- INSERT INTO topscore VALUES(@idj,@idje,@score)
- END
- ELSE
- BEGIN
- SET @scoremax = (SELECT scoremax FROM topscore t
- JOIN JEUX je ON je.idJeux=t.idJeux7
- WHERE je.titre=@titre AND t.idJoueur=@idj)
- PRINT 'Score existant : ' + CONVERT(VARCHAR,@scoremax)
- PRINT 'Score : ' + CONVERT(VARCHAR, @score)
- IF (@score > @ scoremax)
- BEGIN
- PRINT 'MAJ'
- SET @idJeuxmax = (SELECT t.idJeux FROM topscore t
- JOIN JEUX j ON j.idJeux = t.idJeux
- WHERE je.titre=@titre AND t.idJoueur=@idj)
- DELETE FROM topscore
- WHERE idJoueur = @idj AND idJeux=@idje
- INSERT INTO topscore
- VALUES(@idj,@idje,@score)
- END
- ELSE
- BEGIN
- PRINT 'PAS MAJ'
- END
- END
- FETCH NEXT FROM curseur INTO @idj,@idje,@score,@titre
- END
- CLOSE curseur
- DEALLOCATE curseur
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement