共用方式為


使用字串函式

您可以在多維度運算式 (MDX) 中幾乎每個物件上使用字串函式。 在預存程式中,您主要使用字串函式,將 物件轉換成字串標記法。 您也可以使用字串函式來評估物件上的字串運算式,以傳回值。

最常使用的字串函式是 Name Uniquename 。 這些函式會分別傳回 物件的名稱和唯一名稱。 大部分是在偵錯計算時用來探索函式所傳回的成員。

範例

下列範例查詢示範如何使用這些函式:

WITH  
//Returns the name of the current Product on rows  
MEMBER [Measures].[ProductName] AS [Product].[Product].CurrentMember.Name  
//Returns the uniquename of the current Product on rows  
MEMBER [Measures].[ProductUniqueName] AS [Product].[Product].CurrentMember.Uniquename  
//Returns the name of the Product dimension  
MEMBER [Measures].[ProductDimensionName] AS [Product].Name  
SELECT  {[Measures].[ProductName],[Measures].[ProductUniqueName],[Measures].[ProductDimensionName]}  
ON COLUMNS,  
[Product].[Product].MEMBERS  ON ROWS  
FROM [Adventure Works]  

Generate 函式可用來在集合的每個成員上執行字串函式,並串連結果。 這在偵錯計算時也很有用,因為它可讓您將集合的內容視覺化。 下列範例示範如何以這種方式使用它:

WITH  
//Returns the names of the current Product and its ancestors up to the All Member  
MEMBER [Measures].[AncestorNames] AS  
GENERATE(  
ASCENDANTS([Product].[Product Categories].CurrentMember)  
, [Product].[Product Categories].CurrentMember.Name, ", ")  
SELECT  
{[Measures].[AncestorNames]}  
ON COLUMNS,  
[Product].[Product Categories].MEMBERS  ON ROWS  
FROM [Adventure Works]  

另一組廣泛使用的字串函式是可讓您轉換包含物件唯一名稱的字串,或解析為物件本身之運算式的字串。 下列範例查詢示範 StrToMember StrToSet 函式如何 執行此動作:

SELECT  
{StrToMember("[Measures].[Inter" + "net Sales Amount]")}  
ON COLUMNS,  
StrToSet("{  
[Product].[Product Categories].[Category].&[3],  
[Product].[Product Categories].[Product].&[477],  
[Product].[Product Categories].[Product].&[788],  
[Product].[Product Categories].[Product].&[708],  
[Product].[Product Categories].[Product].&[711]  
}")  
ON ROWS  
FROM [Adventure Works]  

注意

應該謹慎使用 StrToMember StrToSet 函式。 如果在計算定義中使用查詢效能,它們可能會導致查詢效能不佳。

另請參閱

產生 (MDX)
名稱 (MDX)
UniqueName (MDX)
函式 (MDX 語法)
使用預存程序 (MDX)
StrToMember (MDX)
StrToSet (MDX)