I'm translating a SQL Server query to Oracle and found an error that does not make sense and I'm not getting it fixed.
The error displayed is as follows:
ORA-00904: "ITM"."NRO_INT_ITEM": identificador inválido
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Erro na linha: 20 Coluna: 42
Query SQL Server (which works)
SELECT
FORMAT(ISNULL(DAQ.DTH_DEMANDA,'9999-01-01'), 'yyyy-MM') + '-01' DT_MOV
, ITM.NRO_INT_ITEM
, ( SELECT COUNT(DISTINCT SQRY_DAQ.NRO_INT_TAREFA) QTD_DEMANDA
FROM TAREFAS SQRY_DAQ
INNER JOIN ITEM_DEMANDADO SQRY_ITD
ON SQRY_DAQ.NRO_INT_TAREFA = SQRY_ITD.NRO_INT_TAREFA
AND SQRY_DAQ.NRO_INT_TAREFA = DAQ.NRO_INT_TAREFA
AND SQRY_ITD.NRO_INT_ITEM = ITD.NRO_INT_ITEM
AND SQRY_ITD.NRO_INT_ITEM = ITM.NRO_INT_ITEM)
QTD_DEMANDA
, 0 QTD_REQUISICAO
, 0 QTD_COMPRA
FROM ITEM ITM
LEFT JOIN ITEM_DEMANDADO ITD
ON ITD.NRO_INT_ITEM = ITM.NRO_INT_ITEM
LEFT JOIN TAREFAS DAQ
ON DAQ.NRO_INT_TAREFA = ITD.NRO_INT_TAREFA
Oracle Query (What's wrong)
SELECT
TO_DATE(NVL(DAQ.DTH_SOME_DATA,'9999-01-01'), 'YYYY-MM') + '-01' DT_MOV
, ITM.NRO_INT_ITEM
, ( SELECT COUNT(DISTINCT SQRY_DAQ.NRO_INT_TAREFA) QTD_DEMANDA
FROM TAREFAS SQRY_DAQ
INNER JOIN ITEM_DEMANDADO SQRY_ITD
ON SQRY_DAQ.NRO_INT_TAREFA = SQRY_ITD.NRO_INT_TAREFA
AND SQRY_DAQ.NRO_INT_TAREFA = DAQ.NRO_INT_TAREFA
AND SQRY_ITD.NRO_INT_ITEM = ITD.NRO_INT_ITEM
AND SQRY_ITD.NRO_INT_ITEM = ITM.NRO_INT_ITEM)
QTD_UM
, 0 QTD_DOIS
, 0 QTD_TRES
FROM ITEM ITM
LEFT JOIN ITEM_DEMANDADO ITD
ON ITD.NRO_INT_ITEM = ITM.NRO_INT_ITEM
LEFT JOIN TAREFAS DAQ
ON DAQ.NRO_INT_TAREFA = ITD.NRO_INT_TAREFA