在MDX查询中获取记录键

时间:2015-01-21 10:55:34

标签: mysql sql mdx

我有一个查询

WITH
MEMBER Measures.ProductKey as [Hand].[Name1].Currentmember.Member_Key
SELECT NON EMPTY
{ [Measures].[Netto], [Measures].[Cost], Measures.ProductKey } Dimension Properties CHILDREN_CARDINALITY,
PARENT_UNIQUE_NAME ON COLUMNS,
NON EMPTY
{ [Hand].[Nazwa1], [Hand].[Nazwa1].Children } Dimension Properties CHILDREN_CARDINALITY,
PARENT_UNIQUE_NAME ON ROWS
FROM [Bild]

此查询返回Netto,Cost和Key。但是当Netto和Cost为null时,我不想显示此记录。没有措施。 ProductKey很好,但我没有钥匙。

1 个答案:

答案 0 :(得分:2)

对计算成员ProductKey的代码进行小幅更改,如下所示:

WITH
MEMBER Measures.ProductKey as 
IIF([Measures].[Netto] = NULL AND [Measures].[Cost] = NULL, NULL, [Hand].[Name1].Currentmember.Member_Key)

//Here have added a condition which first checks the values of other two measures. 
//If they are NULL, it sets the value of ProductKey as NULL as well. 
//The NON EMPTY clause then does its job of removing the row of data from output.

SELECT NON EMPTY
{ [Measures].[Netto], [Measures].[Cost], Measures.ProductKey } Dimension Properties CHILDREN_CARDINALITY,
PARENT_UNIQUE_NAME ON COLUMNS,
NON EMPTY
{ [Hand].[Nazwa1], [Hand].[Nazwa1].Children } Dimension Properties CHILDREN_CARDINALITY,
PARENT_UNIQUE_NAME ON ROWS
FROM [Bild]