Error: More than one value was returned by a subquery

0

Could you help me identify the error:

  

SELECT Failed. 3669: More than one value was returned by a subquery.

  SELECT

(SELECT ID_FUNC
FROM P_ISIDB.TB_DIM_FUNCIONARIO 
INNER JOIN P_ISIDB.TB_STG_VNDA
ON P_ISIDB.TB_STG_VNDA.COD_FUNC  = P_ISIDB.TB_DIM_FUNCIONARIO.COD_FUNC)

,(SELECT ID_PROD
FROM P_ISIDB.TB_DIM_PRODUTO
INNER JOIN P_ISIDB.TB_STG_VNDA
ON P_ISIDB.TB_STG_VNDA.COD_PROD  = P_ISIDB.TB_DIM_PRODUTO.COD_PROD)

   ,DATA_VENDA AS DT_VNDA

   ,STG_VNDA.VALOR_VENDA

   ,STG_VNDA.IMPOSTO

   ,STG_VNDA.QTD_ITENS

   ,(STG_VNDA.VALOR_VENDA - ((STG_VNDA.VALOR_VENDA * STG_VNDA.IMPOSTO) / 100)) 
    AS VL_LDQA

   ,CASE
   WHEN 
     (STG_VNDA.QTD_ITENS = '' OR
       STG_VNDA.QTD_ITENS = 0)
     THEN 0
    ELSE 
    (STG_VNDA.VALOR_VENDA  / STG_VNDA.QTD_ITENS)
 END  AS  VL_UNITARIO

 FROM P_ISIDB.TB_STG_VNDA STG_VNDA
    
asked by anonymous 22.10.2018 / 19:40

1 answer

3

You have to relate your subqueries to query main:

SELECT (SELECT ID_FUNC
          FROM P_ISIDB.TB_DIM_FUNCIONARIO 
         WHERE STG_VNDA.COD_FUNC = P_ISIDB.TB_DIM_FUNCIONARIO.COD_FUNC) AS ID_FUNC
     , (SELECT ID_PROD
          FROM P_ISIDB.TB_DIM_PRODUTO
         WHERE STG_VNDA.COD_PROD  = P_ISIDB.TB_DIM_PRODUTO.COD_PROD) AS ID_PROD
     , DATA_VENDA AS DT_VNDA
     , STG_VNDA.VALOR_VENDA
     , STG_VNDA.IMPOSTO
     , STG_VNDA.QTD_ITENS
     , (STG_VNDA.VALOR_VENDA - ((STG_VNDA.VALOR_VENDA * STG_VNDA.IMPOSTO) / 100)) AS VL_LDQA
     , CASE
         WHEN (STG_VNDA.QTD_ITENS = '' OR STG_VNDA.QTD_ITENS = 0) THEN 0
         ELSE (STG_VNDA.VALOR_VENDA  / STG_VNDA.QTD_ITENS)
       END AS VL_UNITARIO
  FROM P_ISIDB.TB_STG_VNDA STG_VNDA
    
22.10.2018 / 21:33