DATAS DE TABELAS DIFERENTES - firebird

SQL

MySQL

Oracle

Firebird

05/01/2022

Estou com um SQL onde tenho BETWEEN data com duas tabelas diferentes uma traz o resultado solicitado já a outra não, me ajudem por favor


SELECT
/*SAIDA*/
GELANSAI.ITEM ITEM_SAIDA,
GECADSAI.DATA DATA_SAIDA,
SUM(GELANSAI.QTDE) QTDE_SAIDA,
SUM(GELANSAI.VLRMED) VLRMED_SAIDA,
GECADSAI.CDC CDC_SAIDA,
/*ITENS*/
I.NOME,
I.UNI_CON,
I.CUSTO VLR_UNI,
GEGRUPOS.NOME GRUPO,
/*DEVOLUCAO*/
GELANDEV.ITEM ITEM_DEV,
GECADDEV.DATA DATA_DEV,
SUM(GELANDEV.QTDE) QTDE_DEV,
SUM(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
GEGRUPOS ON GEGRUPOS.COD=I.GRU
INNER JOIN
GELANDEV ON GELANDEV.DATA=GECADSAI.DATA
LEFT JOIN
GECADDEV ON GECADDEV.ID=GELANDEV.ID_GECADDEV
WHERE
GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
AND GECADSAI.ANO=:ANO
AND GECADSAI.MES=:MES
AND GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND GECADDEV.CDC BETWEEN :CDC1 AND :CDC2
AND (COALESCE(GELANSAI.CONSOL,'''''''')=''''T'''' OR COALESCE(GECADSAI.CONSOL,'''''''')=''''T'''')
GROUP BY
GELANSAI.ITEM,
GECADSAI.DATA,
GECADSAI.CDC,
I.NOME,
I.CUSTO,
I.UNI_CON,
GEGRUPOS.NOME,
GELANDEV.ITEM,
GECADDEV.DATA,
GECADDEV.CDC
ORDER BY
GECADSAI.CDC,
I.NOME,
GECADSAI.DATA
Marcos Batista

Marcos Batista

Curtidas 0
POSTAR