Output comparison value from a procedure : Procedure « Procedure Function « SQL / MySQL






Output comparison value from a procedure

       


CREATE TABLE EmployeeS(
         EmployeeNO       INTEGER      NOT NULL,
         NAME           CHAR(15)     NOT NULL,
         INITIALS       CHAR(3)      NOT NULL,
         BIRTH_DATE     DATE                 ,
         SEX            CHAR(1)      NOT NULL,
         JOINED         SMALLINT     NOT NULL,
         STREET         VARCHAR(30)  NOT NULL,
         HOUSENO        CHAR(4)              ,
         POSTCODE       CHAR(6)              ,
         TOWN           VARCHAR(30)  NOT NULL,
         PHONENO        CHAR(13)             ,
         LEAGUENO       CHAR(4)              ,
         PRIMARY KEY    (EmployeeNO)           );
         

CREATE   TABLE PENALTIES
        (PAYMENTNO      INTEGER      NOT NULL,
         EmployeeNO       INTEGER      NOT NULL,
         PAYMENT_DATE   DATE         NOT NULL,
         AMOUNT         DECIMAL(7,2) NOT NULL,
         PRIMARY KEY    (PAYMENTNO)          );
         
                  
DELIMITER $$

CREATE PROCEDURE LARGEST
   (OUT T CHAR(10))
BEGIN
   IF (SELECT COUNT(*) FROM EmployeeS) >
      (SELECT COUNT(*) FROM PENALTIES) THEN
      SET T = 'EmployeeS';
   ELSEIF (SELECT COUNT(*) FROM EmployeeS) =
          (SELECT COUNT(*) FROM PENALTIES) THEN
      SET T = 'EQUAL';
   ELSE
      SET T = 'PENALTIES';
   END IF;
END$$


DELIMITER ;


drop table EmployeeS;
drop table penalties; 
drop procedure LARGEST;

   
    
    
    
    
    
    
  








Related examples in the same category

1.Using an OUT parameter
2.Creating a Single-Statement Procedure
3.Calling a Single-Statement Procedure
4.Creating a Multistatement Stored Procedure
5.The ALTER statement lets you change the characteristics of a stored procedure
6.To remove a stored procedures, use the DROP statement
7.Calculate the power in procedure
8.Cleanup table with procedure
9.Compare value in a procedure
10.Find out the age with procedure
11.Syntax for Changing store procedures
12.Syntax for Creating store procedures
13.Drop table by procedure