Parametros de Pesquisa ?[resolvido]

2 respostas
juniorsatanas

[img]https://lh6.googleusercontent.com/-wPwlLrEf4Eg/UAlqgUxrOgI/AAAAAAAAIDg/KY-W_pb5n_8/s587/m1.png[/img]
São 2 pesquisas uma para cada campo, quer dizer são 2 parametros de entrada 1 para cada pesquisa por cpf (pNu_Cpf) e por codigo (pContrato)

A perguta é como fazer uma critéria ou HQL, para campos diferentes e para pesquisas diferentes ?
Mas eu uso um unico botão para ativar o evento.
Eu tenho uma View no meio que faz todo serviço, ela ta no meio do select, eu fiz uma mapa dela, ta ok.
Esses campos são da View grande parte deles !

Eu fiz esse curso e rodei, me traz perfeitamente o que eu quero.. PLSQL e Fodástico !

QUERO FAZER UMA PESQUISA DINÂMICA !

Obrigado..

cursor filtroCpf is
--colocada para tirar tipo de atendimento odontologia
select u.nm_pessoa_razao_social_u
,u.cd_usuario
,u.fl_tipo_pessoa_u
from vw_usuarios u
,tb_tipo_rede_atendimento r
,tb_plano_pai pp
,tb_plano p
where
u.nu_cgc_cpf_t = to_number(pNu_Cpf)
and u.fl_status_usuario = 2
and p.cd_plano = u.cd_plano
and pp.cd_plano_pai = p.cd_plano_pai
and r.cd_tipo_rede_atendimento = pp.cd_tipo_rede_atendimento
and pp.cd_tipo_rede_atendimento <> 'OD'
and r.ds_tipo_rede_atendimento <> 'ODONTOLOGIA';

cursor filtroContrato is
select u.nm_pessoa_razao_social_u
,u.cd_usuario
,u.fl_tipo_pessoa_u
from vw_usuarios u
,tb_tipo_rede_atendimento r
,tb_plano_pai pp
,tb_plano p
where u.nu_ordem_usuario = pContrato
and u.fl_status_usuario = 2
and p.cd_plano = u.cd_plano
and pp.cd_plano_pai = p.cd_plano_pai
and r.cd_tipo_rede_atendimento = pp.cd_tipo_rede_atendimento
and pp.cd_tipo_rede_atendimento <> 'OD'
and r.ds_tipo_rede_atendimento <> 'ODONTOLOGIA';

ESTE AQUI FOI UM TESTE QUE FIZ:

@SuppressWarnings(&quot;rawtypes&quot;)
@Name(value = &quot;usuarioService&quot;)
public class UsuarioServiceImpl extends AppServiceImpl{

	static final long serialVersionUID = 1L;
	 		
				public List ValidaUsuariosCpf(VwUsuarios vwusuarios)throws Exception{   
			        try {  
			            Session session = (Session) getSession();  
			            StringBuilder hql = new StringBuilder();  
			            hql.append(&quot; SELECT&quot;);  
			            hql.append(&quot; u.nm_pessoa_razao_social_u&quot;);  
			            hql.append(&quot; u.cd_usuario&quot;);  
			            hql.append(&quot; u.fl_tipo_pessoa_u&quot;);  
			            hql.append(&quot; FROM&quot;);  
			            hql.append(&quot; VW_USUARIOS u,&quot;);  
			            hql.append(&quot; TB_TIPO_REDE_ATENDIMENTO r,&quot;);  
			            hql.append(&quot; TB_PLANO_PAI pp,&quot;);  
			            hql.append(&quot; TB_PLANO p&quot;);  
			            hql.append(&quot; WHERE&quot;);  
			            hql.append(&quot; u.nu_cgc_cpf_t = :nuCgcCpf&quot;);  
			            hql.append(&quot; AND&quot;);  
			            hql.append(&quot; u.fl_status_usuario = 2&quot;);  
			            hql.append(&quot; AND&quot;);  
			            hql.append(&quot; cd_plano = cd_plano&quot;);  
			            hql.append(&quot; AND&quot;);  
			            hql.append(&quot; p.cd_plano = u.cd_plano&quot;);  
			            hql.append(&quot; AND&quot;);  
			            hql.append(&quot; pp.cd_plano_pai = p.cd_plano_pai&quot;);  
			            hql.append(&quot; AND&quot;);  
			            hql.append(&quot; r.cd_tipo_rede_atendimento = pp.cd_tipo_rede_atendimento&quot;);  
			            hql.append(&quot; AND&quot;);  
			            hql.append(&quot; pp.cd_tipo_rede_atendimento &lt;&gt; 'OD' &quot;);  
			            hql.append(&quot; AND&quot;);  
			            hql.append(&quot; r.ds_tipo_rede_atendimento &lt;&gt; 'ODONTOLOGIA&quot;);  
			            Query query=  (Query) session.createQuery(hql.toString());  
			            query.setParameter(&quot;nuCgcCpf&quot;, vwusuarios.getNuCgcCpf());  
			            return query.list();
			          
			        } catch (Exception e) {  
			            throw new Exception(&quot;Erro ao buscar CPF &quot; + e.getMessage());  
			        }  
		}
}

2 Respostas

juniorsatanas

up !

G

Man,

Será que o uso do COALESCE não te ajudaria…

SELECT t FROM TABLE t WHERE t.column = COALESCE(VAR_1, VAR2)

Criado 20 de julho de 2012
Ultima resposta 23 de jul. de 2012
Respostas 2
Participantes 2