MySQL IN function but my parameter comes a string

0

Hello,

I have a procedure that receives some parameters, among them I need to receive a list of codes, which are 10 at most. But in the query, I'm trying to

WHERE value IN (value1, value2), but since it is a string this does not work.

I'd like to know how I could handle this string by taking the quotation marks. Exactly in this line: (tp.cod_type IN ( values ) OR p_cod_tipo_guarda = 0) AND tp.ind_ativo = 1) AND

SELECT SQL_CALC_FOUND_ROWS
    a.cod_area,
    a.nom_area,
    tp.cod_tipo_guarda,
    tp.nom_tipo_guarda,
    utp.ind_incluir,
    utp.ind_alterar,
    utp.ind_consultar,
    utp.ind_excluir,
    utp.ind_relatorio,
    utp.ind_alerta_venc,
    COUNT(a1.cod_area) AS users_dono,
    COUNT(a2.cod_area) AS users_backup
FROM 
    tipo_guarda tp
  INNER JOIN AREA a ON tp.cod_area = a.cod_area AND a.cod_area != p_nega
  INNER JOIN usuario u ON u.cod_usuario = p_cod_usuario
  LEFT JOIN usuario_tipo_guarda utp ON utp.cod_tipo_guarda = tp.cod_tipo_guarda AND utp.cod_usuario = u.cod_usuario
  LEFT JOIN AREA a1 ON a1.cod_usu_dono = p_cod_usuario AND a.cod_area = a1.cod_area
  LEFT JOIN AREA a2 ON a2.cod_usu_backup = p_cod_usuario AND a.cod_area = a2.cod_area
WHERE 
    (utp.cod_usuario = p_cod_usuario OR utp.cod_usuario IS NULL) AND
    ((tp.cod_tipo_guarda IN(**valores**) OR p_cod_tipo_guarda = 0) AND tp.ind_ativo = 1 ) AND
    ((a.cod_area = p_cod_area OR p_cod_area = 0) AND a.ind_ativo = 1 ) AND
    ((a.cod_usu_backup = p_cod_dono_backup OR p_cod_dono_backup = 0) OR (a.cod_usu_dono = p_cod_dono_backup OR p_cod_dono_backup = 0)) AND
(a.cod_perfil = p_cod_perfil OR p_cod_perfil = 0)
    AND (u.cod_perfil <> 1 ) AND (u.cod_perfil <> 5 )
    
asked by anonymous 25.10.2017 / 21:13

1 answer

0

This resolves:

 ((tp.cod_tipo_guarda IN(TRIM(BOTH "'" FROM valores)) OR p_cod_tipo_guarda = 0) AND tp.ind_ativo = 1 )
    
25.10.2017 / 21:27