You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and a.institucion_codigo= and a.beca_fecha_hora='')' at line 15-> CREATE TEMPORARY TABLE tmp_rep_beca AS (SELECT DISTINCT a.beca_codigo,a.beca_clave,b.institucion_nombre,d.taller_nombre, case WHEN a.beca_estado = '1' THEN 'Generada' else 'Utilizada' END as estado, case when a.beca_estado='1' then '' else Concat(g.persona_nombres,' ',g.persona_apellido_paterno,' ',ifnull(g.persona_apellido_materno,'')) end as participante, a.beca_fecha_hora, e.inscripcion_estado, CASE WHEN a.beca_estado = 2 and inscripcion_estado = 3 then 'NO' ELSE 'SI' end as pasar, e.tipo_inscripcion from beca a LEFT JOIN institucion b on a.institucion_codigo = b.institucion_codigo LEFT JOIN taller d on a.taller_codigo = d.taller_codigo LEFT OUTER JOIN inscripcion e on a.beca_codigo = e.beca_codigo LEFT JOIN usuario f on e.usuario_codigo = f.usuario_codigo LEFT JOIN persona g on f.persona_codigo = g.persona_codigo where a.taller_codigo = and a.institucion_codigo= and a.beca_fecha_hora='');