多次元表現(MDX)では、ほぼすべてのオブジェクトに文字列関数を使用できます。 ストアドプロシージャでは、主にオブジェクトを文字列表現に変換するために文字列関数を使用します。 また、文字列関数を使ってオブジェクト上の文字列式を評価し、値を返すこともできます。
最も広く使われている文字列関数は Name と Uniquenameです。 これらの関数はそれぞれオブジェクトの名前と一意の名前を返します。 主に、関数がどのメンバーを返しているかを検出するために計算のデバッグ時に使われます。
Examples
以下の例クエリはこれらの関数の使い方を示しています。
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]
生成関数は、集合のすべてのメンバーに対して文字列関数を実行し、結果を連結するために使用できます。 これは計算のデバッグ時にも有用で、集合の内容を可視化できます。 以下の例が、このように使う方法を示しています。
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]
Note
StrToMemberとStrToSetの関数は注意して使用すべきです。 計算定義内で使用するとクエリ性能が低下することがあります。