处理MDX OPENQUERY,开头的标识符太长。最大长度为128

时间:2015-02-10 15:11:30

标签: sql-server-2008 mdx

使用openquery时遇到问题。我想选择带有它名称的列,但名称太长,因为有很多级别

SELECT 
     A."[Dimension].[NAMEOFLEVEL1].[NAMEOFLEVEL2].[NAMEOFLEVEL3].[NAMEOFLEVEL4].[NAMEOFLEVEL5].[NAMEOFLEVEL6]" AS Acc2 
FROM OPENQUERY(CUBEX,
        'SELECT 
            ({
                [Dimension].[NAMEOFLEVEL1].[NAMEOFLEVEL2].[NAMEOFLEVEL3].[NAMEOFLEVEL4].[NAMEOFLEVEL5].[NAMEOFLEVEL6]
            }) DIMENSION PROPERTIES MEMBER_KEY 
            ON COLUMNS, 
            NON EMPTY (
                [TIME].[MONTH]
            ) DIMENSION PROPERTIES MEMBER_KEY 
            ON ROWS
        FROM [MyTable] 
    ') A

错误如下:

以'[Dimension]开头的标识符。[NAMEOFLEVEL1]。[NAMEOFLEVEL2]。[NAMEOFLEVEL3]。[NAMEOFLEVEL4]。[NAMEOFLEVEL5]。[NAMEOFLEVEL6]'太长。最大长度为128。

2 个答案:

答案 0 :(得分:0)

一个可行的解决方法是从使用User Hierarchy切换到具有更小标识符的等效Attribute Hierarchy

--USER HIERARCHY EXAMPLE
SELECT 
     "[Date].[Date - Calendar Month].[Calendar Month].[MEMBER_CAPTION]"
FROM OPENQUERY(linkedName,
'
SELECT 
  {[Measures].[xxx]} ON 0
 ,NON EMPTY 
    [Date].[Date - Calendar Month].[Calendar Month].MEMBERS ON 1
FROM [OurCube];')


--ATTRIBUTE HIERARCHY EXAMPLE - NOT MUCH SMALLER IN OUR CUBE
SELECT 
     "[Date].[Calendar Month].[Calendar Month].[MEMBER_CAPTION]"
FROM OPENQUERY(linkedName,
'
SELECT 
  {[Measures].[xxx]} ON 0
 ,NON EMPTY 
    [Calendar Month].[Calendar Month].MEMBERS ON 1
FROM [OurCube];')

也许你的缩短了:

SELECT 
     A."[Dimension].[NAMEOFLEVEL6].[NAMEOFLEVEL6]" AS Acc2 
FROM OPENQUERY(CUBEX,
        'SELECT 
            ({
                [Dimension].[NAMEOFLEVEL6].[NAMEOFLEVEL6]
            }) DIMENSION PROPERTIES MEMBER_KEY 
            ON COLUMNS, 
            NON EMPTY (
                [TIME].[MONTH]
            ) DIMENSION PROPERTIES MEMBER_KEY 
            ON ROWS
        FROM [MyTable] 
    ') A

答案 1 :(得分:0)

这不是OPENQUERY的限制。它是SQL column name的限制 - 实际上是128个字符。

但是,您的情况更容易 - 无需列出所有层次结构以在输出中包含其名称

SELECT 
 A."[Dimension].[NAMEOFLEVEL1].[MEMBER_CAPTION]" as Level1,
 A."[Dimension].[NAMEOFLEVEL2].[MEMBER_CAPTION]" as Level2
 ...
 FROM OPENQUERY(CUBEX,
    'SELECT 
        ({
            [Dimension].[NAMEOFLEVEL6].members
        }) DIMENSION PROPERTIES MEMBER_KEY 
        ON COLUMNS, 
        NON EMPTY (
            [TIME].[MONTH]
        ) DIMENSION PROPERTIES MEMBER_KEY 
        ON ROWS
    FROM [MyTable] 
') A

如果在MDX中遇到非常长的名称(假设Dimension全名+ Member_CAPTION用作列名),则将您的级别包装在名称较短的集合中。

SELECT 
 A."[Measures].[allLevels].[MEMBER_CAPTION]" AS Acc2 
 FROM OPENQUERY(CUBEX,
    'with member allLevels as
      (
          [Dimension].[NAMEOFLEVEL1].[NAMEOFLEVEL2].[NAMEOFLEVEL3].[NAMEOFLEVEL4].[NAMEOFLEVEL5].[NAMEOFLEVEL6].members
      )

      SELECT 
        ({
           [Measures].[allLevels]
        }) DIMENSION PROPERTIES MEMBER_KEY 
        ON COLUMNS, 
        NON EMPTY (
            [TIME].[MONTH]
        ) DIMENSION PROPERTIES MEMBER_KEY 
        ON ROWS
    FROM [MyTable] 
') A