Table is not recognized in Join

Asked

Viewed 50 times

0

I changed the query, because the table TAKB437T_HIER_SAP is not to be used. This came later, but I still have problems recognizing in Join. This is query, being that GE is where I’m having problems. Below is the current query

SELECT 
           COMP2.PKSF_COMP_ORGAN AS COD_UO,
           COMP2.ATSF_CO_PORT_EXT AS DESC_UO,
           COMP2.FKSF_SUPERIOR_HIER AS COD_SUP,
           CASE
              WHEN COMP2.FKSF_FUNCAO_NIVEL = EMP.FKSF_FUNCAO  THEN 1
           END
              AS SUPERIOR,
           QUAL.PKSF_FUNCAO_NIVEL AS COD_CARGO,
           QUAL.ATND_FUNCAO_SAP AS COD_CARGO_SAP,
           NVL(QUAL.ATSF_FUN_PORT_EXT, 'NÃO CADASTRADO') AS DESC_CARGO,
           EMP.PKSF_CHAPA AS COD_FUNC,
           EMP.ATSF_NOME AS DESC_FUNC, 
           GE.ATSF_NOME AS GESTOR,
           NVL(E.ATSF_GRAU, EMP.FKSF_GRAU) AS GRAU_FUNC,
              EMP.ATND_SALAR1 AS SAL_ATUAL,
           COMP2.NIVEL
        FROM     
        ( 
            SELECT PKSF_CHAPA, ATSF_NOME, FKSF_FUNCAO, FKND_COMP_ORGAN, ATDT_DEMISSAO, ATND_SALAR1, FKSF_GRAU
            FROM PANA101V_EMPREGADO
            WHERE PKSF_CHAPA NOT IN(    SELECT PKND_NUMERO_PESSOAL 
                                        FROM TAKB132T_EMPREGADO_AFASTAMENTO 
                                        WHERE FKND_MOTIVO IN(6, 7) AND SYSDATE BETWEEN ATDT_DE AND ATDT_ATE)
            UNION ALL
            (SELECT '999', 'POSIÇÃO NÃO OCUPADA', '999',COMP2.PKSF_COMP_ORGAN, NULL, NULL, NULL 
            FROM 
               DUAL, (    SELECT   COMP.PKSF_COMP_ORGAN,
                        COMP.ATSF_CO_PORT_EXT,
                        CASE
                        WHEN COMP.PKSF_COMP_ORGAN <> 20061607 THEN  NVL(TRIM(COMP.FKSF_FUNCAO_NIVEL), 999)
                        END AS FKSF_FUNCAO_NIVEL,
                        COMP.FKSF_SUPERIOR_HIER,
                        LEVEL AS NIVEL,
                        COMP.ATSF_DT_CANCEL_CO
                 FROM   PANA004T_COMPONENT COMP
                --WHERE   COMP.ATSF_DT_CANCEL_CO = 0
           CONNECT BY   PRIOR COMP.PKSF_COMP_ORGAN = COMP.FKSF_SUPERIOR_HIER
           START WITH   COMP.PKSF_COMP_ORGAN = NVL(20047213 ,20061607)) COMP2

           WHERE COMP2.FKSF_FUNCAO_NIVEL = '999'
           AND   COMP2.ATSF_DT_CANCEL_CO = 0)
            )      EMP

            LEFT JOIN(SELECT EMP.ATSF_NOME, EMP.PKSF_CHAPA FROM PANA101V_EMPREGADO EMP 
                      LEFT JOIN PANA004T_COMPONENT C ON EMP.FKND_COMP_ORGAN = C.FKSF_SUPERIOR_HIER)GE ON EMP.PKSF_CHAPA = GE.PKSF_CHAPA

        LEFT JOIN TAKB100T_EMPREGADO E ON E.PKND_NUMERO_PESSOAL = EMP.PKSF_CHAPA
              LEFT JOIN
                 PANA001T_QUALIFICA QUAL
              ON EMP.FKSF_FUNCAO = QUAL.PKSF_FUNCAO_NIVEL
           RIGHT JOIN
               (    SELECT   COMP.PKSF_COMP_ORGAN,
                        COMP.ATSF_CO_PORT_EXT,
                        CASE
                        WHEN COMP.PKSF_COMP_ORGAN <> 20061607 THEN  NVL(TRIM(COMP.FKSF_FUNCAO_NIVEL), 999)
                        END AS FKSF_FUNCAO_NIVEL,
                        COMP.FKSF_SUPERIOR_HIER,
                        LEVEL AS NIVEL,
                        COMP.ATSF_DT_CANCEL_CO
                 FROM   PANA004T_COMPONENT COMP
                WHERE   COMP.ATSF_DT_CANCEL_CO = 0
           CONNECT BY   PRIOR COMP.PKSF_COMP_ORGAN = COMP.FKSF_SUPERIOR_HIER
           START WITH   COMP.PKSF_COMP_ORGAN = NVL(20047213 ,20061607)) COMP2

           ON COMP2.PKSF_COMP_ORGAN = EMP.FKND_COMP_ORGAN 

           LEFT JOIN(  SELECT
                 C.PKSF_COMP_ORGAN, E.ATSF_NOME
             FROM PANA101V_EMPREGADO E 
             INNER JOIN PANA004T_COMPONENT C ON E.FKND_COMP_ORGAN = C.FKSF_SUPERIOR_HIER) GE
             ON GE.PKSF_COMP_ORGAN = EMP.FKND_COMP_ORGAN
             --WHERE C.PKSF_COMP_ORGAN = 20000988


        WHERE   ( QUAL.PKSF_FUNCAO_NIVEL NOT IN ( 'MU2', '8WY')  OR  QUAL.PKSF_FUNCAO_NIVEL IS NULL )
          AND   COMP2.ATSF_DT_CANCEL_CO = 0
    ORDER BY    COMP2.NIVEL, COMP2.ATSF_CO_PORT_EXT, SUPERIOR;  

The whole issue is the Manager that is coming in the result of the query, is the same as the employee, ie if DESC_FUNC = MANOEL then MANAGER = MANOEL and so on. What I did wrong in my query?

NOTE: In the COMPONENT table I have the key PKSF_COMP_ORGAN and in this same table I have FKSF_SUPERIOR_HIER that says that this code is the top. But COMPONENT is what we call UO, which is not a person, but a kind of area, where in the EMPLOYEES table I can have several employees in a UO. This is what I tried to put in the query.

  • Which version of oracle?

  • @Brunowarmling, 11g

  • In the second Join try a JOIN instead of the IN , until the 11 , the 12 do not know this subselect does not allow reference to the original table. In such cases as this supervisor prefer the use of functions sql gets cleaner , just write a Function with a quick sql.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.