MDAC 2.5 SDK - OLE DB Programmer's Reference
Chapter 24: Multidimensional Expressions


 

Longer Lifetime and Scope: Named Sets and Calculated Members

The scope of the named sets and calculated members specified in the previous section is just the MDX statement in which they appear. Consequently, their lifetime is also limited to the life of the query execution.

It is frequently useful to have named sets and calculated members available for the life of a session and visible to all queries in that session. When used with the user-interface–related set functions, named sets provide a powerful mechanism to create queries that not only preserve the state but also provide an efficient method to process user-interface operations. For more information on how to do this, see "Preserving State During User-Interface Operations" in this section.

To create a named set or a calculated member with longer scope and lifetime, use the following syntax:

<create_formula_statement>:= CREATE [scope] <formula_specification>

The syntax for <formula_specification> is exactly the same as the syntax used in creating named sets and calculated members. The <create_formula_statement> creates a named set or a named member.

The scope and lifetime of this created entity depends on the value of scope. There are two possible values of scope:

Note   See also "Visibility in Schema Rowsets" in this chapter.

As an example, the following MDX statement creates the same dataset that is specified in the section "SalesData Example" in Chapter 21, "OLE DB for OLAP Concepts":

CREATE SET SalesCube.ColumnsAxisSet AS CROSSJOIN({Venkatrao, Netz},
   {USA_North.CHILDREN, USA_South, Japan})
CREATE SET SalesCube.RowsAxisSet AS {Qtr1.CHILDREN, Qtr2, Qtr3, 
   Qtr4.CHILDREN}
SELECT ColumnsAxisSet ON COLUMNS, RowsAxisSet ON ROWS
FROM SalesCube
WHERE (Sales, [1991], Products.[All])

The following rules determine the semantics of named sets and members that are created by using <create_formula_statement>: