“Invalid column name” error on SQL statement from OpenQuery results

前端 未结 4 846
不思量自难忘°
不思量自难忘° 2020-12-18 18:25

I\'m trying to perform a SQL query through a linked SSAS server. The initial query works fine:

SELECT \"Ugly OLAP name\" as \"Value\" 
FROM OpenQuery( OLAP,         


        
相关标签:
4条回答
  • 2020-12-18 19:05

    Oh, bummer. I just saw, you select AS FOO. Don't you need a HAVING claus in this case?

    SELECT whatever AS value FROM table HAVING value > 1;
    

    I still would not use "value". But to be sure, look it up in your docs!

    0 讨论(0)
  • 2020-12-18 19:11

    This should work:

    SELECT A.Value
    FROM (
    SELECT "Ugly OLAP name" as "Value" 
    FROM OpenQuery( OLAP, 'OLAP Query')
    ) AS a
    WHERE a.Value > 0
    

    It's not that Value is a reserved word, the problem is that it's a column alias, not the column name. By making it an inline view, "Value" becomes the column name and can then be used in a where clause.

    0 讨论(0)
  • 2020-12-18 19:20

    You're using "Value" as a column alias, and I don't think the alias can appear in the where clause. It's simply used to name the returned column value. Your where clause should refer to the original column name:

    SELECT "Ugly OLAP name" as "Value" 
    FROM OpenQuery( OLAP, 'OLAP Query')
    WHERE "Ugly OLAP name" > 0
    
    0 讨论(0)
  • 2020-12-18 19:23

    I can vouch for leaving it out of GROUP BY. Good news is, it works just fine being a plain old selected alias.

    0 讨论(0)
提交回复
热议问题