如果我运行以下内容:
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月”?
答案 0 :(得分: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
...
答案 1 :(得分: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解决方案,有一个way。