使用預存程序 (MDX)Using Stored Procedures (MDX)

您可以擴充 Analysis ServicesAnalysis Services 和多維度運算式 (MDX) 的功能,其方式是撰寫 .NET 預存程序或使用者定義函數。You can extend the functionality of Analysis ServicesAnalysis Services and Multidimensional Expressions (MDX) by writing .NET stored procedures or user-defined functions. 如需詳細資訊,請參閱ADOMD.NET 伺服器程式設計For more information, see ADOMD.NET Server Programming

當您要參考或呼叫預存程序時,必須指定函數的名稱,並在後面加上括號。When you reference or call a stored procedure, you specify the function name followed by parentheses. 您可以在括號中指定稱為引數的運算式,它會提供要傳送給參數的資料。Within the parentheses, you can specify expressions called arguments that provide the data to be passed into the parameters. 當您呼叫函數時,必須提供所有參數的引數值,而指定引數值的順序必須跟使用者自訂函數中定義參數的順序相同。When you call a function, you must supply argument values for all of the parameters, and you must specify the argument values in the same sequence in which the parameters are defined in the user-defined function.

下列範例查詢假設您在 Analysis ServicesAnalysis Services 伺服器上已註冊一個名為 SampleAssembly 的組件:The following example query assumes that you have an assembly named SampleAssembly registered on your Analysis ServicesAnalysis Services Server:

SELECT SampleAssembly.RandomSample([Geography].[State-Province].Members, 5) on ROWS,   
[Date].[Calendar].[Calendar Year] on COLUMNS  
FROM [Adventure Works]  
WHERE [Measures].[Reseller Freight Cost]  

注意

預存程序是中使用的術語Analysis ServicesAnalysis Services針對這些類型的函式。Stored procedure is the terminology used in Analysis ServicesAnalysis Services for these types of functions. 舊版Analysis ServicesAnalysis Services呼叫這些函數做為類型使用者定義函式Earlier versions of Analysis ServicesAnalysis Services called these types of functions as user-defined functions.

預存程序類型Types of stored procedures

Analysis ServicesAnalysis Services 支援 COM 及 CLR 兩種組件。supports both COM and CLR assemblies. 因為 CLR 組件具備進階的安全性,所以建議使用 CLR 組件。CLR assemblies are recommended because of the enhanced security available to CLR assemblies. 如果伺服器上已安裝 Microsoft Office Excel,還可以使用 Excel 函數。If Microsoft Office Excel is installed on the server, Excel functions are also available.

注意

Microsoft Visual Basic for Applications (VBA) COM 組件會自動註冊。Microsoft Visual Basic for Applications (VBA) COM Assemblies are registered automatically.

另請參閱See Also

函式(MDX 語法)Functions (MDX Syntax)