Mysql IN function but my parameter comes a string

Asked

Viewed 71 times

0

Hello,

I have a trial that receives a few parameters, among them I need to receive a list of codes, which are 10 at most. But in the consultation, I’m trying to

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

I would like to know how to treat this string, apart from the quotation marks. Right on this line: ((tp.cod_type IN(values) OR p_cod_guard type = 0) AND tp.ind_active = 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 )

1 answer

0

That solves:

 ((tp.cod_tipo_guarda IN(TRIM(BOTH "'" FROM valores)) OR p_cod_tipo_guarda = 0) AND tp.ind_ativo = 1 )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.