我用多个UNION ALL语句进行查询,但它没有显示应该显示的所有结果。SELECT语句都有相同数量的列、相同的别名和相同的数据类型(为了确定起见,我已经尝试过使用CAST(。只有一个SELECT语句在两个不同的列中使用CASE,这就是与其他语句不同的地方。我试图将其导出到子选择,但没有成功。事实上,如果我自己管理它们,它们运行得很好。如果我删除这个包含这两个CASE的SELECT语句,并保留其余的语句,它运行得很好。有很多联合,所以我只发布有问题的SELECT和其他一个联合,因为它们几乎都是一样的。
我所做的只是从不同的事件中提取价值观,比如员工的税收、员工的工资和不同的调整,只是为了更清楚地了解我在做什么。由于法律原因,我无法提供真实数据。是什么使它不能与其他SELECT一起运行?
这是一个给我问题
SELECT
CASE
WHEN TCL.CONTADEB IS NOT NULL THEN TCL.CONTADEB
WHEN TCL.CONTACRED IS NOT NULL THEN TCL.CONTACRED
END AS CONTA_CTB
, CASE
WHEN TCL.CONTADEB IS NOT NULL THEN CR.VALOREVENTO
END AS DEBITO
, CASE
WHEN TCL.CONTACRED IS NOT NULL THEN CR.VALOREVENTO
END AS CREDITO
, FP.NOMEFUNC AS FUNCIONARIO
, EV.DESCREVENTO || ' - ' || EXTRACT(MONTH FROM PC.COMPET) || '/' || EXTRACT(YEAR FROM PC.COMPET) || ' ' || FP.NOMEFUNC AS OBSERVACAO
, LCTB.DESCRLOCALCTB AS LOCAL_CONTABIL
, CC.DESCRCENTROCUSTO AS CENTRO_CUSTO
, EXTRACT(YEAR FROM PC.DATAFINALFOLHA) || lpad(EXTRACT(MONTH FROM PC.DATAFINALFOLHA), '2', '0') || EXTRACT(DAY FROM PC.DATAFINALFOLHA) AS VENCIMENTO
FROM CALCULORATEIO CR
LEFT JOIN CENTROCUSTO CC
ON CC.CODIGOEMPRESA = CR.CODIGOEMPRESA AND CC.CODIGOCENTROCUSTO = CR.CODIGOCENTROCUSTO
LEFT JOIN EVENTO EV
ON EV.CODIGOEVENTO = CR.CODIGOEVENTO
LEFT JOIN PERIODOCALCULO PC
ON PC.CODIGOEMPRESA = CR.CODIGOEMPRESA AND PC.CODIGOPERCALCULO = CR.CODIGOPERCALCULO
LEFT JOIN FUNCCONTRATO FC
ON FC.CODIGOEMPRESA = CR.CODIGOEMPRESA AND FC.CODIGOFUNCCONTR = CR.CODIGOFUNCCONTR
LEFT JOIN FUNCPESSOA FP
ON FP.CODIGOFUNCPESSOA = FC.CODIGOFUNCPESSOA
LEFT JOIN FUNCLOCALCTB FLC
ON FLC.CODIGOEMPRESA = CR.CODIGOEMPRESA AND FLC.CODIGOFUNCCONTR = CR.CODIGOFUNCCONTR
AND FLC.DATAOPCAO = (SELECT MAX(FLC1.DATAOPCAO) FROM FUNCLOCALCTB FLC1 WHERE FLC1.CODIGOEMPRESA = FLC.CODIGOEMPRESA AND
FLC1.CODIGOFUNCCONTR = FLC.CODIGOFUNCCONTR AND FLC1.DATAOPCAO <= PC.DATAINICIALFOLHA)
LEFT JOIN LOCALCONTABIL LCTB
ON LCTB.CODIGOEMPRESA = FLC.CODIGOEMPRESA AND LCTB.CODIGOLOCALCTB = FLC.CODIGOLOCALCTB
LEFT JOIN EVENTOTABELACONTABIL EVT
ON EVT.CODIGOEVENTO = CR.CODIGOEVENTO AND EVT.CODIGOGRUPOTABELACONTABIL = 0
LEFT JOIN TABCTBLOCALCTB TCL
ON TCL.CODIGOEMPRESA = FLC.CODIGOEMPRESA AND TCL.CODIGOTABCTB = EVT.CODIGOTABCTB AND TCL.CODIGOLOCALCTB = FLC.CODIGOLOCALCTB
WHERE
CR.CODIGOEMPRESA = :CodigoEmpresa.n AND
CR.CODIGOPERCALCULO = :CodigoPerCalculo.n
还有一个:
SELECT
CASE
WHEN PFR.DIFERPGTO > 0 THEN '1608'
ELSE '1612'
END AS CONTA_CTB
, PFR.DIFERPGTO AS DEBITO
, PFR.DIFERPGTO AS CREDITO
, FP.NOMEFUNC AS FUNCIONARIO
, 'Diferença Pgto 13' || ' - ' || EXTRACT(MONTH FROM PC.COMPET) || '/' || EXTRACT(YEAR FROM PC.COMPET) || ' ' || FP.NOMEFUNC AS OBSERVACAO
, LCTB.DESCRLOCALCTB AS LOCAL_CONTABIL
, CC.DESCRCENTROCUSTO AS CENTRO_CUSTO
, EXTRACT(YEAR FROM PC.DATAFINALFOLHA) || lpad(EXTRACT(MONTH FROM PC.DATAFINALFOLHA), '2', '0') || EXTRACT(DAY FROM PC.DATAFINALFOLHA) AS VENCIMENTO
FROM PROVISAO13RAT PFR
LEFT JOIN FUNCCONTRATO FC
ON FC.CODIGOEMPRESA = PFR.CODIGOEMPRESA AND FC.CODIGOFUNCCONTR = PFR.CODIGOFUNCCONTR
LEFT JOIN FUNCPESSOA FP
ON FP.CODIGOFUNCPESSOA = FC.CODIGOFUNCPESSOA
LEFT JOIN PERIODOCALCULO PC
ON PC.CODIGOEMPRESA = PFR.CODIGOEMPRESA AND PC.COMPET = PFR.COMPET
LEFT JOIN CENTROCUSTO CC
ON CC.CODIGOEMPRESA = PFR.CODIGOEMPRESA AND CC.CODIGOCENTROCUSTO = PFR.CODIGOCENTROCUSTO
LEFT JOIN FUNCLOCALCTB FLC
ON FLC.CODIGOEMPRESA = PFR.CODIGOEMPRESA AND FLC.CODIGOFUNCCONTR = PFR.CODIGOFUNCCONTR
AND FLC.DATAOPCAO = (SELECT MAX(FLC1.DATAOPCAO) FROM FUNCLOCALCTB FLC1 WHERE FLC1.CODIGOEMPRESA = FLC.CODIGOEMPRESA AND
FLC1.CODIGOFUNCCONTR = FLC.CODIGOFUNCCONTR AND FLC1.DATAOPCAO <= PC.DATAINICIALFOLHA)
LEFT JOIN LOCALCONTABIL LCTB
ON LCTB.CODIGOEMPRESA = FLC.CODIGOEMPRESA AND LCTB.CODIGOLOCALCTB = FLC.CODIGOLOCALCTB
WHERE
PFR.CODIGOEMPRESA = :CODIGOEMPRESA.n AND
PFR.COMPET = :DATAINICIAL.d AND
PFR.DIFERPGTO <> 0
我在这些表中使用的主表都有相同的结构,除了那一个(我粘贴在这里的第一个代码(,这可能是问题的一部分吗?
WHERE子句都通过公司代码和计费日期进行筛选,这对所有子句都是一样的。如果缺少任何信息,我会尽我所能向他们提供。
好吧,原来是因为表的结构不同,对我来说没有多大意义,但它现在可以工作了