Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Dec 8, 2003

MDX Essentials: Basic Set Functions: The Intersect() Function - Page 3

By William Pearson

Practice

The Basics

To reinforce our understanding of the basics we have covered so far, we will use the Intersect() function in a manner that illustrates its operation through a multi-step example: we will build from a pair of simple select queries, to a combination of the two in an Intersect() illustration. We will then explore the use of the ALL flag to force retainage of duplicates.

We will call upon the MDX Sample Application again, as our tool to construct and execute the MDX we examine, and to view the results datasets we obtain.

1.  Start the MDX Sample Application.

2.  Clear the top area (the Query pane) of any queries or remnants that might appear.

3.  Ensure that FoodMart 2000 is selected as the database name in the DB box of the toolbar.

4.  Select the HR cube in the Cube drop-down list box.

Let's assume for our practice example that we want to replicate the data we discussed in the example used in the syntax section. Using this simple illustration will allow us to be certain of our "answer," without the distraction of any complicating factors. To reiterate, our objective will be to present total Number of Employees, a measure that is stored in the HR cube, for three Northeastern states, intersected with two states that form a subset of the three.

We will begin by composing a simple query to select the employee population figure for the three-state set, followed by a query to select the same information for the two-state subset of the initial three-state set. We will then intersect the two sets with the Intersect() function, noting the results immediately.

5.  Type the following query into the Query pane:


-- MDX14-1:  Tutorial Query Step 1
SELECT
{[Measures].[Number of Employees]} ON COLUMNS,
{([Store].[All Stores].[USA].[OR]),([Store].[All Stores].[USA].[CA]), 
   ([Store].[All Stores].[USA].[WA])} ON ROWS
FROM HR

The purpose of this query is to simply generate the "first half" of the pair of sets that we intend to "cross" in the Intersect() query that will follow.

6.  Execute the query by clicking the Run Query button in the toolbar.

The Results pane is populated by Analysis Services, and the dataset shown in Illustration 1 appears.


Illustration 1: Result Dataset - Initial Half of Set Pair to be "Intersected"

We see the total Number of Employees for three Northeastern states returned (actually for 1997, the default member of the Time slicer).

7.  Select File -> Save As, name the file MDX14-1, and place it in a meaningful location.

8.  Select File --> New from the main menu.

A new, blank query pane appears.


-- MDX14-2:  Tutorial Query Step 2
SELECT
{[Measures].[Number of Employees]} ON COLUMNS,
{([Store].[All Stores].[USA].[OR]), ([Store].[All Stores].[USA].[WA])} ON ROWS
FROM HR

The purpose of this query is to simply generate the "second half" of the pair of sets that we intend to "cross" in the Intersect() query, which we will construct next.

10.  Execute the query by clicking the Run Query button in the toolbar.

The Results pane is populated by Analysis Services, and the dataset shown in Illustration 2 appears.


Illustration 2: Result Dataset - The "Second Half" of the Pair of Candidate Sets

11.  Save the file as MDX14-2.



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM