GARANTIR DESCONTO

Fórum SQL (consulta auxiliar) #352175

21/01/2008

0

Seguinte, na clausula:

select distinct a.mcs_socio_id, a.mcs_evento_id, c.eve_descricao, d.pes_matr, d.pes_nom, ( select sum( b.mcs_vl_lanc ) from tb_movcontasocio b where ( (b.mcs_socio_id = a.mcs_socio_id) and (b.mcs_lan_estorno = 0) and (b.status <> ´E´) and (b.mcs_evento_id = a.mcs_evento_id) ) ) as total from tb_movcontasocio a inner join tb_eventos c on (a.mcs_evento_id = c.eve_id) inner join tb_cadpessoas d on (a.mcs_socio_id = d.pes_id)


Como fazer para que seja retornados apenas valores diferentes de NULL
na consulta auxiliar?
Dá certo se repetir todo o código dela na clausula where, tipo:

... inner join tb_cadpessoas d on (a.mcs_socio_id = d.pes_id) where ( select sum( b.mcs_vl_lanc ) from tb_movcontasocio b where ( (b.mcs_socio_id = a.mcs_socio_id) and (b.mcs_lan_estorno = 0) and (b.status <> ´E´) and (b.mcs_evento_id = a.mcs_evento_id) ) ) > 0


Mas fica muito feio.


Luciano.badoe

Luciano.badoe

Responder

Posts

21/01/2008

Djjunior

tente algo assim:
select distinct a.mcs_socio_id, a.mcs_evento_id, c.eve_descricao, d.pes_matr, d.pes_nom, 
from tb_movcontasocio a 
join tb_eventos c on (a.mcs_evento_id = c.eve_id) 
join tb_cadpessoas d on (a.mcs_socio_id = d.pes_id)
join (select mcs_socio_id, mcs_evento_id, sum(mcs_vl_lanc ) from tb_movcontasocio 
      where (mcs_lan_estorno = 0) and (status <> ´E´) ) b 
on (b.mcs_socio_id = a.mcs_socio_id) and 
     (b.mcs_evento_id = a.mcs_evento_id) 
) 
) as total 




Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar