Error: More than one value was returned by a subquery

Asked

Viewed 47 times

0

Could help me identify the mistake:

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
  • (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)

  • Where is the WHERE in subqueries?

1 answer

3


You have to relate your subqueries with the queryleading:

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
  • 1

    Thanks Sorack! I got your comment, it worked.

Browser other questions tagged

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