HOW TO MAKE A VARIABLE REGEXP

1
SELECT  CONCAT(per.apellido," ",per.nombre) AS alumno,per.dni as
dni,car.descripcion,per.correo , jor.descripcion as nombrej
FROM persona as per
INNER JOIN inscripcion as ins on ins.id_persona=per.id_persona
INNER JOIN jornada as jor ON jor.id_jornada=ins.id_jornada
INNER JOIN carrera as car ON car.id_carrera=per.id_carrera
where jor.id_jornada = 1 AND per.apellido regexp '^[a-i]'
ORDER BY per.apellido;

Good afternoon everyone.

I need the values of the regular expression in this query to be variable, try using variables in an SP and it does not work.

Could someone please give me some guidance on how I could do it?

Thank you.

edition1: I forgot to mention that I work with the Mysql engine Version 5.7.21

    
asked by francisco castillo 31.03.2018 в 23:48
source

1 answer

2

you could try the following:

SET  @a =  '^[a-i]' ;

SELECT  CONCAT(per.apellido," ",per.nombre) AS alumno,per.dni as
dni,car.descripcion,per.correo , jor.descripcion as nombrej
FROM persona as per
INNER JOIN inscripcion as ins on ins.id_persona=per.id_persona
INNER JOIN jornada as jor ON jor.id_jornada=ins.id_jornada
INNER JOIN carrera as car ON car.id_carrera=per.id_carrera
where jor.id_jornada = 1 AND per.apellido REGEXP @a  
ORDER BY per.apellido;

Greetings.

    
answered by 03.04.2018 в 16:00