Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galera estou com uma dificuldade em um select, estou criando um campo de pesquisa que irá envolver combinações de campos preenchidos, por exemplo, consultar apenas clientes, ou data inicial e data final, ou data inicial data final e cliente, ou valor.
no caso da consulta de cliente tudo bem, consulta de datas inicial e final sem problemas também porém quando pesquiso por data inicial data final e cliente, o resultado vem total puxa todas as datas fora do que pesquisei e todos os clientes.
Segue o select se alguém puder me ajudar a montar o final dele.
$termo = $_POST['termopesquisa'];
$termo2 = $_POST['termopesquisa2'];
$termo3 = $_POST['termopesquisa3'];
$termo4 = $_POST['termopesquisa4'];
$termo5 = $_POST['termopesquisa5'];
$termo6 = $_POST['termopesquisa6'];
$termo7 = $_POST['termopesquisa7'];
$termo8 = $_POST['termopesquisa8'];
$termo9 = $_POST['termopesquisa9'];
$termo = addslashes($termo);
$termo2 = trim($termo2);
$termo3 = addslashes($termo3);
$termo4 = addslashes($termo4);
$termo5 = addslashes($termo5);
$termo6 = addslashes($termo6);
$termo7 = addslashes($termo7);
$termo8 = addslashes($termo8);
$termo9 = addslashes($termo9);
$stmt = ociparse($connect,"select sel.cliente,
sel.name,
sel.entrada,
sel.saida,
sel.tipo_doc,
sel.nf_ou_dta,
sel.valor,
sel.Peso_Bruto,
sel.Cod_Comiss,
sel.bez from (select x.cliente,
k.name,
x.entrada,
x.saida,
x.tipo_doc,
x.nf_ou_dta,
x.valor,
x.Peso_Bruto,
x.Cod_Comiss,
di.bez
from --Importaçao
(select de.id_klient cliente,
k.name,
io.time_in entrada,
(select max(io.time_out)
from in_out io, in_out_pos iop
where io.lager = iop.lager
and io.id_in_out = iop.id_in_out
and io.art_in_out = 'CC' --PARA ESPECIFICAR A DATA DA SAÍDA ''
and iop.typ_document = ('DI') --ESPECIFICA O TIPO DE DOCUMENTO
and iop.document = de.nr_di) saida,
'DI' tipo_doc,
de.nr_di nr_doc,
iop.document NF_OU_DTA,
(select A.VALOR_CIF
from anliefpos a
where a.lager = de.lager
and a.bruecke_1 = de.lote_ad)VALOR,
de.gross_weight Peso_Bruto,
de.id_dispatcher Cod_Comiss,
dis.bez nome_comissaria
from desmembr de,
desmembrpos dp,
in_out io,
in_out_pos iop,
we w,
klienten k,
dispatcher dis
where de.lager = dp.lager
and dis.id_dispatcher = de.id_dispatcher
and de.id_klient = k.id_klient
and de.id_desmemb = dp.id_desmemb
and de.id_klient = dp.id_klient
and io.lager = iop.lager
and io.id_in_out = iop.id_in_out
and de.id_klient = io.id_klient
and io.art_in_out = 'LI'
and iop.typ_document = 'DTA'
and iop.lager = w.lager
and iop.typ_document = w.typ_doc
and iop.document = w.nr_doc
and de.id_klient = w.id_klient
and dp.id_klient = w.id_klient
and w.nr_lieferschein = de.lote_ad
--and iop.document = '1234567811'
and trunc(io.time_in) between '01-jan-11' and '31-mai-14'
union
--exportação--
select dde.id_klient cliente,
k.name,
io.time_in entrada,
(select max(io.time_out)
from in_out io, in_out_pos iop
where io.lager = iop.lager
and io.id_in_out = iop.id_in_out
and io.art_in_out in ('CA', 'CCE') --PARA ESPECIFICAR A TIPO DA SAÍDA LS125
and iop.typ_document = 'DDE' --ESPECIFICA O TIPO DE DOCUMENTO
and iop.document = dde.nr_dde) saida,
'DDE' tipo_doc,
dde.nr_dde nr_doc,
inv.nr_nf NF_OU_DTA,
dde.preis Valor,
dde.gew,
dde.despachante Cod_Comiss,
dis.bez nome_comissaria
from dde_reg dde,
invoice inv,
in_out io,
in_out_pos iop,
klienten k,
dispatcher dis
where dde.NR_DDE = inv.NR_DDE(+)
and dis.id_dispatcher = dde.despachante
and dde.id_klient = k.id_klient
and dde.LAGER = inv.LAGER(+)
and dde.id_klient = inv.id_klient_dde(+)
and io.lager = iop.lager
and io.id_in_out = iop.id_in_out
and io.art_in_out = 'LI'
and iop.typ_document = 'NF'
and inv.nr_nf = iop.document) x,
Klienten k,
dispatcher di
where x.cliente = k.id_klient
and x.Cod_Comiss = di.id_dispatcher
) sel
where cliente = '$termo3'
or entrada like '$termo'
or entrada >='$termo' and entrada <='$termo2'
or entrada >='$termo' and entrada <='$termo2' and cliente = '$termo3'
order by entrada asc"
Carregando comentários...