2

如果我运行以下命令:

WITH MEMBER [Date].[Date - Calendar Month].[Last Completed Month] AS
     IIF( Day(Now()) = 1,
         TAIL([Date].[Date - Calendar Month].[Calendar Month],1)(0),
         TAIL([Date].[Date - Calendar Month].[Calendar Month],2)(0)
    )
SELECT
       NON EMPTY
          [Date].[Date - Calendar Month].[Last Completed Month]
       ON COLUMNS
FROM  [OurCube]
WHERE ([Measures].[NumUsers])

它返回这个:

在此处输入图像描述

是否可以更改脚本,以便使用实际月份“2013 年 6 月”而不是使用“最后完成的月份”作为列标题?

4

2 回答 2

1

不要认为这是可能的;CAPTION 属性似乎不接受 MDX 表达式。

WITH MEMBER XX as 42, CAPTION = 'Answer'
SELECT XX ...

根据 MDX 的使用方式,您可以添加显示名称的计算成员

WITH 
  MEMBER [LCM Value] as  (...)
  MEMBER [LCM Name ] as  (...).name

SELECT
 { [LCM Value], [LCM Name] } on 0
...
于 2013-07-08T22:55:54.820 回答
0
declare @cur_date   varchar(20), @linked_server varchar(20) = 'YourLinkedServer'
set @cur_date=datename(M,GETDATE()) + ' '+ datename(YYYY,GETDATE())
declare @mdx_query varchar(max) = 
'WITH MEMBER [Date].[Date - Calendar Month].[Last Completed Month] AS
     IIF( Day(Now()) = 1,
         TAIL([Date].[Date - Calendar Month].[Calendar Month],1)(0),
         TAIL([Date].[Date - Calendar Month].[Calendar Month],2)(0)
    )
SELECT
       NON EMPTY
   [Date].[Date - Calendar Month].[Last Completed Month] as ''' + @cur_date + '''
       ON COLUMNS
FROM  [OurCube]
WHERE ([Measures].[NumUsers])'

set @mdx_query='Select * from openrowset('''+@linked_server+''','''+@mdx_query+''')'
EXEC sp_executesql @mdx_query

至于纯 MDX 解决方案,有一种方法.

于 2013-07-08T13:46:59.507 回答