Filtering during iteration
This example shows how to move filtering from dimension query to foreach
iteration:
OLAPConnection connection = OLAPCreateNamedConnection("");
string errorMessage = "";
int errorCode = 0;
string sDimension = "Product";
string sizeAttribute = "SIZE";
string nameAttribute = "NAME";
try
{
OLAPElementList list = on connection select all from sDimension order by nameAttribute asc;
OLAPElementList listLow = CreateOLAPElementList();
OLAPElementList listHigh = CreateOLAPElementList();
foreach (OLAPElement e in list where (OLAPGetStringAttribute(connection, e, sizeAttribute) < "200"))
{
Append(listLow, e);
}
foreach (OLAPElement e in list where (OLAPGetStringAttribute(connection, e, sizeAttribute) > "200"))
{
Append(listHigh, e);
}
}
catch (errorMessage, errorCode)
{
WriteLine("Exception: " + errorMessage);
}
OLAPDisconnect(connection);
Here, the filtering is in a foreach
statement, so the element list is not
affected by the filtering. This eliminates the necessity to execute the same query twice,
each time with a different filter.