Case
EssbaseのMDX Case関数は、条件式を開始します。CASEを使用して実行できる条件付きテストには、単純なケース式と検索ケース式の2種類があります。
構文
単純なケース式は、case_operandを評価し、WHEN句またはELSE句で指定した値に基づいて結果を返します。ケース式の結果は、値式またはセットになります。ELSE句が指定されず、WHEN句のいずれも一致しない場合、空の値または空のセットが返されます。
CASE
case_operand
simple_when_clause...
[ else_clause ]
END
検索ケース式では、各WHEN句は、検索条件と、その検索条件が満たされた場合に返される結果を指定します。WHEN句は、指定した順序で評価されます。結果は、検索条件がTRUEと評価される最初のWHEN句から返されます。結果は、値式またはセットになります。ELSE句が指定されず、WHEN句の検索条件がいずれもTRUEと評価されない場合、空の値または空のセットが返されます。
CASE
searched_when_clause...
[ else_clause ]
END
パラメータ
- case_operand
-
評価する式。
- simple_when_clause
-
1つ以上のWHEN文またはTHEN文。構文:
WHEN when_operand THEN result
-
when_operand: 値式。
-
result: 数値式、文字列値式、またはセット。
-
- else_clause
-
オプション。構文:
ELSE numeric_value_expression | set | string_value_expression
- searched_when_clause
-
1つ以上のWHEN文またはTHEN文。構文:
WHEN search_condition THEN result
-
search_condition: 値式。
-
result: 数値式、文字列値式、またはセット。
-
例
単純なケース式の例
次の問合せでは、計算されたメンバー[Measures].[ProductOunces]
は、Productディメンションの現在のメンバーのOunce属性の値に基づいて評価されます。
WITH MEMBER [Measures].[ProductOunces] AS
'Case Product.CurrentMember.Ounces
when 32 then 32
when 20 then 20
when 16 then 16
when 12 then 12
else 0
end'
SELECT
{ [Measures].[ProductOunces] } ON COLUMNS,
{ [Product].Members } ON ROWS
FROM Sample.Basic
この問合せが返す結果は次のとおりです。
表4-43 MDX例からの出力グリッド
(軸) | ProductOunces |
---|---|
Product | 0 |
Colas | 0 |
Cola | 12 |
Diet Cola | 12 |
Caffeine Free Cola | 16 |
Root Beer | 0 |
Old Fashioned | 12 |
Diet Root Beer | 16 |
Sarsaparilla | 12 |
Birch Beer | 16 |
Cream Soda | 0 |
Dark Cream | 20 |
Vanilla Cream | 20 |
Diet Cream | 12 |
Fruit Soda | 0 |
Grape | 32 |
Orange | 32 |
Strawberry | 32 |
Diet Drinks | 0 |
Diet Cola | 0 |
Diet Root Beer | 0 |
Diet Cream | 0 |
検索ケース式の例
次の問合せは、製品をProfitに基づいて様々な利益カテゴリに分割し、各製品のカテゴリを返します。
WITH MEMBER [Measures].[ProfitCategory] AS
' Case
when Profit > 10000 then 4
when Profit > 5000 then 3
when Profit > 3000 then 2
else 1
end'
SELECT
{ [Measures].[ProfitCategory] } ON COLUMNS,
{ [Product].Members } ON ROWS
FROM Sample.Basic
この問合せが返す結果は次のとおりです。
表4-44 MDX例からの出力グリッド
(軸) | ProfitCategory |
---|---|
Product | 4 |
Colas | 4 |
Cola | 4 |
Diet Cola | 3 |
Caffeine Free Cola | 1 |
Root Beer | 4 |
Old Fashioned | 3 |
Diet Root Beer | 4 |
Sarsaparilla | 2 |
Birch Beer | 2 |
Cream Soda | 4 |
Dark Cream | 4 |
Vanilla Cream | 1 |
Diet Cream | 4 |
Fruit Soda | 4 |
Grape | 4 |
Orange | 3 |
Strawberry | 1 |
Diet Drinks | 4 |
Diet Cola | 3 |
Diet Root Beer | 4 |
Diet Cream | 4 |
関連項目