MySQL Stored Procedure: Boolean Logic in IF THEN

Posted by xncroft on Stack Overflow See other posts from Stack Overflow or by xncroft
Published on 2010-05-12T18:17:37Z Indexed on 2010/05/12 18:24 UTC
Read the original article Hit count: 383

Filed under:
|
|

I'm looking for the proper syntax (if this is possible in MySQL stored procedures) for using logical operators in an IF THEN statement. Here's something along the lines of what I would like to do, but I'm not certain if I should type "OR" or "||" in the IF ... THEN clause:

DELIMITER $$

CREATE PROCEDURE `MyStoredProc` (_id INT)
BEGIN

  DECLARE testVal1 INT DEFAULT 0;
  DECLARE testVal2 INT DEFAULT 0;

  SELECT value1, value2 INTO testVal1, testVal2 
    FROM ValueTable 
   WHERE id = _id;

 IF testVal1 > 0 OR testVal2 > 0 THEN

   UPDATE ValueTable 
      SET value1 = (value1+1) 
    WHERE id=_id;

 END IF;

END$$

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql