Advertisement
ecto

Untitled

Sep 14th, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.34 KB | None | 0 0
  1. DELETE topscore
  2.  
  3. DECLARE
  4.     @idj INT,
  5.     @idje INT,
  6.     @score INT,
  7.     @titre VARCHAR(30),
  8.     @scoremax INT,
  9.     @idjeuxmax INT
  10.  
  11. DELCARE curseur CURSOR FOR
  12.     SELECT p.idJoueur,p.idJeux, score, titre FROM PARTIE p
  13.     JOIN JEUX je ON p.idJeux=je.idJeux
  14.  
  15. OPEN curseur
  16. FETCH NEXT FROM curseur INTO
  17. @idj,@idje,@score,@titre
  18.  
  19. WHILE @@FETCH_STATUS = 0
  20. BEGIN
  21.     IF NOT EXISTS (SELECT * FROM topscore t
  22.                     JOIN JEUX je ON t.idJeux=je.idJeux
  23.                     WHERE je.titre = @titre AND t.idJoueur=@idj)
  24.         BEGIN
  25.             PRINT 'Insert score : ' + CONVERT(VARCHAR,@score)
  26.             INSERT INTO topscore VALUES(@idj,@idje,@score)
  27.         END
  28.     ELSE
  29.         BEGIN
  30.         SET @scoremax = (SELECT scoremax FROM topscore t
  31.                             JOIN JEUX je ON je.idJeux=t.idJeux7
  32.                             WHERE je.titre=@titre AND t.idJoueur=@idj)
  33.         PRINT 'Score existant : ' + CONVERT(VARCHAR,@scoremax)
  34.         PRINT 'Score : ' + CONVERT(VARCHAR, @score)
  35.         IF (@score > @ scoremax)
  36.             BEGIN
  37.                 PRINT 'MAJ'
  38.                 SET @idJeuxmax = (SELECT t.idJeux FROM topscore t
  39.                                     JOIN JEUX j ON j.idJeux = t.idJeux
  40.                                     WHERE je.titre=@titre AND t.idJoueur=@idj)
  41.                 DELETE FROM topscore
  42.                 WHERE idJoueur = @idj AND idJeux=@idje
  43.                 INSERT INTO topscore
  44.                 VALUES(@idj,@idje,@score)
  45.             END
  46.         ELSE
  47.             BEGIN
  48.                 PRINT 'PAS MAJ'
  49.             END
  50.     END
  51.     FETCH NEXT FROM curseur INTO @idj,@idje,@score,@titre
  52. END
  53.  
  54. CLOSE curseur
  55.  
  56. DEALLOCATE curseur
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement