RESULTADO INVALIDO
No campo AND GELANSAI.CONSOL='T' e AND GELANDEV.CONSOL='T' estão me trazendo valores zerados, mas quando deixo apenas o GELANSAI.CONSOL='T' me traz valores, mas preciso de adicionar o outro campo, alguém me ajuda
SELECT
/*SAIDA*/
GELANSAI.ITEM ITEM_SAIDA,
GECADSAI.DATA DATA_SAIDA,
GELANSAI.QTDE QTDE_SAIDA,
GELANSAI.VLRMED VLRMED_SAIDA,
GECADSAI.CDC CDC_SAIDA,
/*ITENS*/
I.NOME,
I.UNI_CON,
I.CUSTO VLR_UNI,
(SELECT FIRST 1 GEGRUPOS.NOME FROM GEGRUPOS WHERE GEGRUPOS.COD = I.GRU) GRUPO,
(SELECT FIRST 1 NOME FROM TBCENCUS WHERE COD=GECADSAI.CDC) CDC,
/*DEVOLUCAO*/
GELANDEV.ITEM ITEM_DEV,
GECADDEV.DATA DATA_DEV,
GELANDEV.QTDE QTDE_DEV,
GELANDEV.VLRMED VLRMED_DEV,
GECADDEV.CDC CDC_DEV
FROM GECADSAI
LEFT JOIN GELANSAI ON GECADSAI.ANO=GELANSAI.ANO
AND GECADSAI.MES=GELANSAI.MES
AND GECADSAI.DOC=GELANSAI.DOC
LEFT JOIN GEITENS I ON GELANSAI.ITEM=I.COD
LEFT JOIN TBCENCUS T ON T.COD=GECADSAI.CDC
LEFT JOIN GELANDEV ON GELANDEV.id_gelansai=GELANSAI.id_gelansai
LEFT JOIN GECADDEV ON GECADDEV.ID=GELANDEV.ID_GECADDEV
WHERE GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND GELANSAI.CONSOL='T'
AND GECADSAI.CONSOL='T'
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
ORDER BY CDC_SAIDA, NOME
SELECT
/*SAIDA*/
GELANSAI.ITEM ITEM_SAIDA,
GECADSAI.DATA DATA_SAIDA,
GELANSAI.QTDE QTDE_SAIDA,
GELANSAI.VLRMED VLRMED_SAIDA,
GECADSAI.CDC CDC_SAIDA,
/*ITENS*/
I.NOME,
I.UNI_CON,
I.CUSTO VLR_UNI,
(SELECT FIRST 1 GEGRUPOS.NOME FROM GEGRUPOS WHERE GEGRUPOS.COD = I.GRU) GRUPO,
(SELECT FIRST 1 NOME FROM TBCENCUS WHERE COD=GECADSAI.CDC) CDC,
/*DEVOLUCAO*/
GELANDEV.ITEM ITEM_DEV,
GECADDEV.DATA DATA_DEV,
GELANDEV.QTDE QTDE_DEV,
GELANDEV.VLRMED VLRMED_DEV,
GECADDEV.CDC CDC_DEV
FROM GECADSAI
LEFT JOIN GELANSAI ON GECADSAI.ANO=GELANSAI.ANO
AND GECADSAI.MES=GELANSAI.MES
AND GECADSAI.DOC=GELANSAI.DOC
LEFT JOIN GEITENS I ON GELANSAI.ITEM=I.COD
LEFT JOIN TBCENCUS T ON T.COD=GECADSAI.CDC
LEFT JOIN GELANDEV ON GELANDEV.id_gelansai=GELANSAI.id_gelansai
LEFT JOIN GECADDEV ON GECADDEV.ID=GELANDEV.ID_GECADDEV
WHERE GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND GELANSAI.CONSOL='T'
AND GECADSAI.CONSOL='T'
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
ORDER BY CDC_SAIDA, NOME
Marcos Batista
Curtidas 0
Melhor post
Emerson Nascimento
06/12/2021
não deveria ser OR no lugar de AND, além de usar COALESCE(), visto que o relacionamento é com LEFT JOIN ?
WHERE GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND (COALESCE(GELANSAI.CONSOL,'')='T' OR COALESCE(GECADSAI.CONSOL,'')='T')
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
ORDER BY CDC_SAIDA, NOME
WHERE GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND (COALESCE(GELANSAI.CONSOL,'')='T' OR COALESCE(GECADSAI.CONSOL,'')='T')
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
ORDER BY CDC_SAIDA, NOME
GOSTEI 1
Mais Respostas
Marcos Batista
06/12/2021
não deveria ser OR no lugar de AND, além de usar COALESCE(), visto que o relacionamento é com LEFT JOIN ?
WHERE GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND (COALESCE(GELANSAI.CONSOL,'')='T' OR COALESCE(GECADSAI.CONSOL,'')='T')
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
ORDER BY CDC_SAIDA, NOME
WHERE GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND (COALESCE(GELANSAI.CONSOL,'')='T' OR COALESCE(GECADSAI.CONSOL,'')='T')
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
ORDER BY CDC_SAIDA, NOME
SERÁ QUE CONSIGO FAZER ISSO COM O BETWEEN DATA TBM ?
SELECT
/*SAIDA*/
GELANSAI.ITEM ITEM_SAIDA,
GECADSAI.DATA DATA_SAIDA,
GELANSAI.QTDE QTDE_SAIDA,
GELANSAI.VLRMED VLRMED_SAIDA,
GECADSAI.CDC CDC_COD,
/*ITENS*/
I.NOME,
I.UNI_CON,
I.CUSTO VLR_UNI,
(SELECT FIRST 1 GEGRUPOS.NOME FROM GEGRUPOS WHERE GEGRUPOS.COD = I.GRU) GRUPO,
(SELECT FIRST 1 NOME FROM TBCENCUS WHERE COD=GECADSAI.CDC) CDC,
/*DEVOLUCAO*/
GELANDEV.ITEM ITEM_DEV,
GECADDEV.DATA DATA_DEV,
GELANDEV.QTDE QTDE_DEV,
GELANDEV.VLRMED VLRMED_DEV,
GECADDEV.CDC CDC_COD
FROM GECADSAI
LEFT JOIN GELANSAI ON GECADSAI.ANO=GELANSAI.ANO
AND GECADSAI.MES=GELANSAI.MES
AND GECADSAI.DOC=GELANSAI.DOC
LEFT JOIN GEITENS I ON GELANSAI.ITEM=I.COD
LEFT JOIN TBCENCUS T ON T.COD=GECADSAI.CDC
LEFT JOIN GELANDEV ON GELANDEV.id_gelansai=GELANSAI.id_gelansai
LEFT JOIN GECADDEV ON GECADDEV.ID=GELANDEV.ID_GECADDEV
WHERE GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
AND GECADDEV.DATA BETWEEN :DATA1 AND :DATA2
AND (COALESCE(GELANSAI.CONSOL,'')='T' OR COALESCE(GECADSAI.CONSOL,'')='T')
ORDER BY CDC, NOME
GOSTEI 0
Emerson Nascimento
06/12/2021
claro.
basta seguir a mesma lógica.
basta seguir a mesma lógica.
GOSTEI 0
Marcos Batista
06/12/2021
claro.
basta seguir a mesma lógica.
basta seguir a mesma lógica.
Segui a mesma lógica, mas não me trouxe resultado, poderia me mostra como ficaria por gentileza ...
GOSTEI 0
Emerson Nascimento
06/12/2021
tente algo assim:
sempre publique o que você já testou, pra evitar de receber uma resposta que você já testou.
AND ( (NOT GECADSAI.DATA IS NULL AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2) OR (NOT GECADDEV.DATA IS NULL AND GECADDEV.DATA BETWEEN :DATA1 AND :DATA2) )
sempre publique o que você já testou, pra evitar de receber uma resposta que você já testou.
GOSTEI 1