共用方式為


使用純量運算式

在多維度運算式 (MDX),純量運算式是一個 MDX 語法元素,評估後就會傳回評估內容中的一個值。

純量運算式包括 MDX 的字串、數值與日期運算式。

純量運算式通常會用於導出成員定義中,因為導出成員必須傳回純量值。下列查詢會顯示 Measures 維度上使用不同純量運算式類型的導出成員範例:

WITH

MEMBER MEASURES.NumericValue AS 10

MEMBER MEASURES.NumericExpression AS 10 + 10

MEMBER MEASURES.NumericExpressionBasedOnMeasure AS [Measures].[Internet Sales Amount] + 10

MEMBER MEASURES.StringValue AS "10"

MEMBER MEASURES.ConcatenatedString AS "10" + "10"

MEMBER MEASURES.StringFunction AS MEASURES.CURRENTMEMBER.NAME

MEMBER MEASURES.TodaysDate AS NOW()

SELECT

{MEASURES.NumericValue,MEASURES.NumericExpression,MEASURES.NumericExpressionBasedOnMeasure,

MEASURES.StringValue, MEASURES.ConcatenatedString, MEASURES.StringFunction, MEASURES.TodaysDate}

ON COLUMNS

FROM [Adventure Works]

量值 (不論是否為導出量值) 可以傳回的唯一資料類型是 OLE Variant 類型。因此,有時您可能需要將量值轉換成特定類型,才能接收您所預期的行為。下列查詢顯示一個這樣的範例:

WITH
//Two calculated measures that return strings
MEMBER MEASURES.NumericString1 AS "10"
MEMBER MEASURES.NumericString2 AS "10"
//In this case, the + operator acts to concatenate the strings
MEMBER MEASURES.Concatenation AS MEASURES.NumericString1 + MEASURES.NumericString2
//Casting one value to an integer with the CINT function causes the second measure
//to be treated as an integer too, so that the + operator now acts to add the values
MEMBER MEASURES.Addition AS CINT(MEASURES.NumericString1) + MEASURES.NumericString2
SELECT
{MEASURES.NumericString1,MEASURES.NumericString2,MEASURES.Concatenation,MEASURES.Addition }
ON COLUMNS
FROM [Adventure Works]

請參閱

概念