Query does not return setted WHERE

Asked

Viewed 30 times

0

I am trying to perform a query to the Informix Database, and it is bringing the data in normally, but it is ignoring the search criteria.

SELECT cnnfcapa.id_nfcapa,   
cnnfcapa.filial, cnnfitem.tpordem, 
cnnfcapa.ordemserv, cnnfcapa.dtnota,  
cnnfcapa.cgccpf, 
cnnfcapa.tppessoa, cnnfcapa.transacao, 
cttransa.mvtotransacao, 
cttransa.tipotransacao, 
cnnfcapa.id_agente, 
cnnfcapa.id_agentvext, 
cnnfitem.descritem, cnnfitem.mercadoria, 
cnnfitem.quantidade, 
cnnfitem.valoritem
FROM cnnfcapa 
INNER JOIN cnnfitem ON 
cnnfcapa.id_nfcapa = cnnfitem.id_nfcapa
INNER JOIN cttransa ON 
cnnfcapa.transacao = cttransa.transacao
WHERE dtnota BETWEEN "01/01/2015" 
AND "31/12/2015"
AND cttransa.mvtotransacao="S" 
AND cttransa.tipotransacao=10 
OR cttransa.tipotransacao=15 
OR cttransa.tipotransacao=30
OR cttransa.tipotransacao=35

The result is like this:

inserir a descrição da imagem aqui

1 answer

1


Their OR are not being interpreted in the way you expect, and are being applied in relation to all AND together. Do so like this:

WHERE dtnota BETWEEN "01/01/2015" AND "31/12/2015"
AND cttransa.mvtotransacao="S" 
AND cttransa.tipotransacao IN(10, 15, 30, 35)
  • 1

    Another thing: I don’t know the details of Informix, but check the documentation to see if you can even use this date format. It would be safer AAAA-MM-DD.

  • It’s a third-party database. I’m only importing this data into my Mysql database. Thanks for the tip

Browser other questions tagged

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