Pergunta

I'm getting the below error when I click save in the Query Editor in PowerPivot 2013. When I validate the the input I'm nonetheless getting: "SQL statement is valid".

OLE DB or ODBC error: No value given for one or more required parameters.. An error occurred while processing table 'SAP bxl'. The current operation was cancelled because another operation in the transaction failed.

Any idea what could be going wrong? Here's the SQL statement:

   SELECT 'A' As "region", 
          [Sheet1$].[Cost Ctr] As "cost center",
          [Sheet1$].[Cost Elem#] AS "cost element",
          [Sheet1$].[Doc# Date] AS "document date",
          sum([Sheet1$].[Val#in rep#cur#]) AS "val" 
     FROM [Sheet1$]
 GROUP BY region, [Sheet1$].[Cost Ctr], [Sheet1$].[Cost Elem#], [Sheet1$].[Doc# Date]
UNION ALL
   SELECT 'B' As "region",
          [Sheet1$].[Cost Center]  As "cost center",
          [Sheet1$].[Cost Element] AS "cost element",
          [Sheet1$].[Document Date] AS "document date",
          sum([Sheet1$].[Val/COArea Crcy]) as "val"
     FROM `C:\a.xlsx`.[Sheet1$]
 GROUP BY region, 
          [Sheet1$].[Cost Center], 
          [Sheet1$].[Cost Element], 
          [Sheet1$].[Document Date]

Many thanks.

Edit: I found the resolution. I can remove the group by "region" parameter and then it seems to work. I thought one always need to group by all the non-aggregated columns?

Foi útil?

Solução

The result column names you define in your SELECT clause don't exist in the GROUP BY clause. SQL's syntax is confusing because the last step of the query is the first thing you write. You should interpret it as

FROM `C:\a.xlsx`.[Sheet1$]
GROUP BY region, 
    [Sheet1$].[Cost Center], 
    [Sheet1$].[Cost Element], 
    [Sheet1$].[Document Date]
SELECT 'B' As "region",
    [Sheet1$].[Cost Center]  As "cost center",
    [Sheet1$].[Cost Element] AS "cost element",
    [Sheet1$].[Document Date] AS "document date",
    sum([Sheet1$].[Val/COArea Crcy]) as "val"

Here, it is obvious that region does not yet exist.

FROM `C:\a.xlsx`.[Sheet1$]
GROUP BY
    [Sheet1$].[Cost Center], 
    [Sheet1$].[Cost Element], 
    [Sheet1$].[Document Date]
SELECT 'B' As "region",
    [Sheet1$].[Cost Center]  As "cost center",
    [Sheet1$].[Cost Element] AS "cost element",
    [Sheet1$].[Document Date] AS "document date",
    sum([Sheet1$].[Val/COArea Crcy]) as "val"

Here, it is also obvious that 'B' (a constant) can be determined without any aggregate functions, because you don't use any columns that aren't part of your GROUP BY clause. Not using any columns at all is merely a special case of not using any columns that aren't part of your GROUP BY clause. :)

What you've done to resolve the problem is exactly what you should have done.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top