0

I want to create a trigger that will allow insert to execute on work hourse (Mon to Fri from 9 am to 5 pm). I currently have this

CREATE DEFINER=`root`@`localhost` TRIGGER `noWorkHour` 
BEFORE INSERT ON `empleado` FOR EACH ROW 
BEGIN

  IF DAYOFWEEK(NOW()) BETWEEN (2, 6) 
  AND CURTIME() BETWEEN '09:00:00' AND '17:00:00' 
  THEN
    SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Solo se pueden ingresar en horario de trabajo';
  END IF;
END

But when I try to insert something, it shows:

/* Error de SQL (1241): Operand should contain 1 column(s) */
/* Affected rows: 0  Filas encontradas: 0  Advertencias: 0  Duración para 0 of 1 query: 0,000 sec. */

I use MariaDB for this.

mustaccio
  • 18,234
  • 16
  • 48
  • 57

1 Answers1

0

After @mustaccio comment, I was messing with other thing rather than the trigger by itself.

Trigger goes as follow:

CREATE DEFINER=`root`@`localhost` TRIGGER `noWorkHour` BEFORE INSERT ON `empleado` FOR EACH ROW BEGIN


IF DAYOFWEEK(NOW()) NOT BETWEEN 2 AND 6 AND CURTIME() NOT BETWEEN '09:00:00' AND '16:00:00' THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Solo se pueden ingresar en horario de trabajo';

END IF;
END