Advertisement
cdsatrian

polling update

Jun 30th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.12 KB | None | 0 0
  1. DELIMITER $
  2. CREATE trigger otomatis after INSERT on inbox
  3.   FOR EACH ROW BEGIN
  4.     DECLARE pilihan VARCHAR(3);
  5.     DECLARE no_pengirim VARCHAR(200);
  6.     SET pilihan=NEW.TextDecoded;
  7.     SET no_pengirim=NEW.SenderNumber;
  8.     IF (SELECT COUNT(*)
  9.         FROM inbox
  10.         WHERE SenderNumber=no_pengirim
  11.           AND TextDecoded=pilihan) > 1 THEN
  12.       INSERT INTO outbox (DestinationNumber,TextDecoded)
  13.         VALUES (no_pengirim , 'Anda sudah pernah Memilih');
  14.     ELSEIF (SELECT COUNT(*)
  15.             FROM inbox
  16.             WHERE SenderNumber=no_pengirim
  17.               AND TextDecoded=pilihan) = 0 THEN
  18.       BEGIN
  19.         UPDATE poll
  20.           SET jumlah = jumlah + 1
  21.           WHERE kode=pilihan;
  22.         INSERT INTO outbox (DestinationNumber,TextDecoded)
  23.           VALUES (no_pengirim , 'Terima Kasih Pilihan Anda Sudah Tersimpan');
  24.       END;  
  25.     ELSEIF (SELECT COUNT(*)
  26.             FROM poll
  27.             WHERE kode=pilihan) = 0 THEN
  28.       INSERT INTO outbox (DestinationNumber,TextDecoded)
  29.         VALUES (no_pengirim , 'Pilihan anda tidak ada dalam list');
  30.     END IF;
  31.   END $
  32. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement