DATA - Firebird
Estou trabalhando nessa query, tenho duas tabelas (GECADSAI - GECADDEV) , quando executo essa query apenas os dados da tabela GECADSAI que me traz valores na data que mencionei, já a tabela GECADDEV traz valores de datas superiores a qual mencionei, ou seja, preciso que as duas tabelas me traga resultados na data mencionada ao executar a query.
SELECT
/*SAIDA*/
GELANSAI.ITEM ITEM_SAIDA,
GECADSAI.DATA DATA,
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,
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 GELANDEV ON GELANDEV.id_gelansai=GELANSAI.id_gelansai
LEFT JOIN GECADDEV ON GECADDEV.ID=GELANDEV.ID_GECADDEV
WHERE GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
AND (COALESCE(GELANSAI.CONSOL,'')='T' OR COALESCE(GECADSAI.CONSOL,'')='T')
ORDER BY CDC,
NOME
SELECT
/*SAIDA*/
GELANSAI.ITEM ITEM_SAIDA,
GECADSAI.DATA DATA,
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,
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 GELANDEV ON GELANDEV.id_gelansai=GELANSAI.id_gelansai
LEFT JOIN GECADDEV ON GECADDEV.ID=GELANDEV.ID_GECADDEV
WHERE GECADSAI.CDC BETWEEN :CDC1 AND :CDC2
AND GECADSAI.DATA BETWEEN :DATA1 AND :DATA2
AND (COALESCE(GELANSAI.CONSOL,'')='T' OR COALESCE(GECADSAI.CONSOL,'')='T')
ORDER BY CDC,
NOME
Marcos Batista
Curtidas 0
Respostas
Emerson Nascimento
25/01/2022
SELECT /*SAIDA*/ LSAI.ITEM ITEM_SAIDA, CSAI.DATA DATA, LSAI.QTDE QTDE_SAIDA, LSAI.VLRMED VLRMED_SAIDA, CSAI.CDC CDC_COD, /*ITENS*/ I.NOME, I.UNI_CON, I.CUSTO VLR_UNI, GRP.NOME GRUPO, CC.NOME CDC, /*DEVOLUCAO*/ LDEV.ITEM ITEM_DEV, CDEV.DATA DATA, LDEV.QTDE QTDE_DEV, LDEV.VLRMED VLRMED_DEV, CDEV.CDC CDC_COD FROM GECADSAI CSAI LEFT JOIN GELANSAI LSAI ON LSAI.ANO=CSAI.ANO AND LSAI.MES=CSAI.MES AND LSAI.DOC=CSAI.DOC LEFT JOIN GEITENS I ON I.COD=LSAI.ITEM LEFT JOIN GELANDEV LDEV ON LDEV.id_gelansai=LSAI.id_gelansai LEFT JOIN GECADDEV CDEV ON CDEV.ID=LDEV.ID_GECADDEV AND CDEV.DATA BETWEEN :DATA1 AND :DATA2 -- TENTE COM ESTA LINHA LEFT JOIN GEGRUPOS GRP ON GRP.COD = I.GRU LEFT JOIN TBCENCUS CC ON CC.COD=CSAI.CDC WHERE CSAI.CDC BETWEEN :CDC1 AND :CDC2 AND CSAI.DATA BETWEEN :DATA1 AND :DATA2 AND (COALESCE(LSAI.CONSOL,'')='T' OR COALESCE(CSAI.CONSOL,'')='T') ORDER BY CSAI.CDC, I.NOME
suponho que GECADSAI sejam saídas/vendas e GECADDEV sejam devoluções.
se for isso, e DEPENDENDO do tipo de análise que se queira fazer, não
é prudente filtrar as devoluções por data; devem ser apresentadas todas
as devoluções. novamente, DEPENDENDO da análise que se queira fazer.
GOSTEI 0