Professional Documents
Culture Documents
Microstrategy Freeform SQL Essentials Co
Microstrategy Freeform SQL Essentials Co
Course Guide
Version: FFSQL-941-Mar14-CG
© 2000–2014 MicroStrategy Incorporated. All rights reserved.
This Course (course and course materials) and any Software are provided “as is” and without express or limited
warranty of any kind by either MicroStrategy Incorporated (“MicroStrategy”) or anyone who has been involved in the
creation, production, or distribution of the Course or Software, including, but not limited to, the implied warranties of
merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the Course
and Software is with you. Should the Course or Software prove defective, you (and not MicroStrategy or anyone else
who has been involved with the creation, production, or distribution of the Course or Software) assume the entire cost
of all necessary servicing, repair, or correction.
In no event will MicroStrategy or any other person involved with the creation, production, or distribution of the Course
or Software be liable to you on account of any claim for damage, including any lost profits, lost savings, or other
special, incidental, consequential, or exemplary damages, including but not limited to any damages assessed against or
paid by you to any third party, arising from the use, inability to use, quality, or performance of such Course and
Software, even if MicroStrategy or any such other person or entity has been advised of the possibility of such damages,
or for the claim by any other party. In addition, MicroStrategy or any other person involved in the creation, production,
or distribution of the Course and Software shall not be liable for any claim by you or any other party for damages
arising from the use, inability to use, quality, or performance of such Course and Software, based upon principles of
contract warranty, negligence, strict liability for the negligence of indemnity or contribution, the failure of any remedy
to achieve its essential purpose, or otherwise.
The Course and the Software are copyrighted and all rights are reserved by MicroStrategy. MicroStrategy reserves the
right to make periodic modifications to the Course or the Software without obligation to notify any person or entity of
such revision. Copying, duplicating, selling, or otherwise distributing any part of the Course or Software without prior
written consent of an authorized representative of MicroStrategy are prohibited.
U.S. Government Restricted Rights. It is acknowledged that the Course and Software were developed at private
expense, that no part is public domain, and that the Course and Software are Commercial Computer Software and/or
Commercial Computer Software Documentation provided with RESTRICTED RIGHTS under Federal Acquisition
Regulations and agency supplements to them. Use, duplication, or disclosure by the U.S. Government is subject to
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at
DFAR 252.227-7013 et. seq. or subparagraphs (c)(1) and (2) of the Commercial Computer Software—Restricted Rights
at FAR 52.227-19, as applicable. The Contractor is MicroStrategy, 1850 Towers Crescent Plaza, Tysons Corner, Virginia
22182. Rights are reserved under copyright laws of the United States with respect to unpublished portions of the
Software.
Copyright Information
Trademark Information
All other company and product names may be trademarks of the respective companies with which they are associated.
Specifications subject to change without notice. MicroStrategy is not responsible for errors or omissions.
MicroStrategy makes no warranties or commitments concerning the availability of future products or versions that
may be planned or under development.
Patent Information
This product is patented. One or more of the following patents may apply to the product sold herein: U.S. Patent Nos.
6,154,766, 6,173,310, 6,260,050, 6,263,051, 6,269,393, 6,279,033, 6,567,796, 6,587,547, 6,606,596, 6,658,093,
6,658,432, 6,662,195, 6,671,715, 6,691,100, 6,694,316, 6,697,808, 6,704,723, 6,741,980, 6,765,997, 6,768,788,
6,772,137, 6,788,768, 6,798,867, 6,801,910, 6,820,073, 6,829,334, 6,836,537, 6,850,603, 6,859,798, 6,873,693,
6,885,734, 6,940,953, 6,964,012, 6,977,992, 6,996,568, 6,996,569, 7,003,512, 7,010,518, 7,016,480, 7,020,251,
7,039,165, 7,082,422, 7,113,993, 7,127,403, 7,174,349, 7,181,417, 7,194,457, 7,197,461, 7,228,303, 7,260,577, 7,266,181,
7,272,212, 7,302,639, 7,324,942, 7,330,847, 7,340,040, 7,356,758, 7,356,840, 7,415,438, 7,428,302, 7,430,562,
7,440,898, 7,486,780, 7,509,671, 7,516,181, 7,559,048, 7,574,376, 7,617,201, 7,725,811, 7,801,967, 7,836,178, 7,861,161,
7,861,253, 7,881,443, 7,925,616, 7,945,584, 7,970,782, 8,005,870, 8,051,168, 8,051,369, 8,094,788, 8,130,918,
8,296,287, 8,321,411 and 8,452,755. Other patent applications are pending.
How to Contact Us
Course Description
This 1-day course covers how to create and use Freeform SQL reports in a
MicroStrategy project. The course assumes an understanding of basic report
development and project design concepts from the Certified Project Designer
track as well as a thorough knowledge of SQL.
After taking this course, students will understand how to implement Freeform
SQL reporting as part of a MicroStrategy project.
• Report developers
Course Prerequisites
Before starting this course, you should be familiar with:
• SQL
Follow-Up Courses
• This course does not have any recommended follow-up courses.
Course Objectives
After completing this course, you will be able to:
• Describe the types of prompts that you can use in Freeform SQL reports,
add new prompts and insert existing prompts into Freeform SQL reports,
and configure prompts as optional. (Page 98)
• Create Freeform SQL reports that use derived and common table
expressions, stored procedures, and non-relational data
sources. (Page 128)
• Explain how permissions are applied for existing project attributes and
Freeform SQL objects in Freeform SQL reports, configure the default
access control list settings for Freeform SQL objects, and use security
filters in Freeform SQL reports. (Page 188)
Content Descriptions
Each major section of this course begins with a Description heading. The
Description introduces you to the content contained in that section.
Learning Objectives
Learning objectives enable you to focus on the key knowledge and skills you
should obtain by successfully completing this course. Objectives are provided
for you at the following three levels:
Lessons
Each lesson sequentially presents concepts and guides you with step-by-step
procedures. Illustrations, screen examples, bulleted text, notes, and
definition tables help you to achieve the learning objectives.
• Review
• Case Study
• Business Scenario
• Exercises
Typographical Standards
The following sections explain the font style changes, icons, and different
types of notes that you see in this course.
Actions
References to screen elements and keys that are the focus of actions are in
bold Arial font style. The following example shows this style:
Code
Sum(sales)/number of months
Data Entry
Keyboard Keys
Press CTRL+B.
New Terms
New terms to note are in regular italic font style. These terms are defined
when they are first encountered in the course material. The following
example shows this style:
Heading Icons
The following heading icons are used to indicate specific practice and review
sections:
— Precedes Exercises
MicroStrategy Courses
Core Courses
• Implementing MicroStrategy: Development and Deployment
Advanced Courses
• MicroStrategy Administration: Configuration and Security
All courses are subject to change. Please visit the MicroStrategy website for the latest
education offerings.
Lesson Description
In this lesson, you will learn about the concept of Freeform SQL and how it can
benefit you in your MicroStrategy reporting environment. You will also learn
about the differences between Freeform SQL reports and standard
MicroStrategy reports. Finally, you will be introduced at a high level to the
topics that are covered in this course.
Lesson Objectives
After completing the topics in this lesson, you will be able to:
• Describe the topics that are covered in this course. (Page 30)
After completing this topic, you will be able to:What Is Freeform SQL?
Explain the purpose of MicroStrategy Freeform SQL reports.
For most reports that you create in MicroStrategy Developer, you design the
report template and filter. Then, based on the objects in the template and
filter, the SQL Engine of MicroStrategy Intelligence Server generates the
appropriate SQL to retrieve the result set from your data warehouse. This
method represents the standard way of creating a MicroStrategy report.
When you create Freeform SQL reports, you can write SQL from scratch, use
previously defined SQL statements, or copy MicroStrategy Engine-generated
SQL from a standard report and modify it as needed.
For more information about specific guidelines for writing SQL for
Freeform SQL reports, see the “Creating Freeform SQL Reports”
lesson starting on page 33.
Since the MicroStrategy SQL Engine can generate SQL that is optimized for
your specific data warehouse platform, why would you want to use Freeform
SQL reports? Although the majority of the reports in your project will be
standard reports, Freeform SQL reports can help you satisfy specific types of
reporting requirements. For example, you can use Freeform SQL reports to
do the following:
• Access data that is stored in operational tables or other data sources that
are not optimized for OLAP analysis
• Access data that is stored in relational databases other than your primary
data warehouse
• Run stored procedures or other existing SQL routines that you already
know work well for specific queries
• Retrieve data from multiple data sources and merge it into a single report
container
You need to assess your environment to determine how to use Freeform SQL
reports in your project so that you can rapidly develop reports, easily
maintain the project, and sustain optimal system performance. Judiciously
creating a few Freeform SQL reports to achieve specific requirements can
provide value to your project. However, creating a large number of Freeform
SQL reports can complicate development and maintenance and potentially
degrade performance.
© 2014 MicroStrategy Inc. What Are the Benefits of Using Freeform SQL? 23
1 Introduction to Freeform SQL Reporting MicroStrategy Freeform SQL Essentials
As you have already learned, you can use Freeform SQL reports in a variety of
ways just as you can standard reports. For example, you can use a Freeform
SQL report as a dataset for a Report Services document. For most
MicroStrategy functionality, Freeform SQL reports behave in the same way
as standard reports. Although a report developer can view the definition of a
Freeform SQL report and easily see how its structure differs from a standard
report, these differences are transparent to end users who interact only with
the result set.
For example, the following image shows the same report result generated
using both a standard and a Freeform SQL report:
Standard and Freeform SQL Report Results
Although the report definitions look very different, they produce the same
result to display to the end user.
Partially Not
Function Supported
Supported Supported
Printing X
Page-by X
Derived metrics X
(MicroStrategy OLAP
Services)
Shortcut metrics X
Sorting X
Subtotals X
Thresholds X
Drilling X
VLDB properties X
Data marting X
Partially Not
Function Supported
Supported Supported
Exporting X
Outline mode X
Custom banding X
Data pivoting X
Custom groups X
Consolidations X
Transformations X
Shortcut Metrics
A shortcut metric enables you to quickly create metrics on the fly using
existing metrics in a report. The following image shows the shortcut metrics
menu:
Shortcut Metrics Menu
• Percent to total
• Transformations
• Rank
In Freeform SQL reports, you can create only percent to total and rank
shortcut metrics. You cannot define transformation shortcut metrics because
they require new SQL to aggregate metric data using the transformation
expressions.
Drilling
You drill on standard reports based on the relationships that you define
between attributes. These relationships enable you to drill down to child
attributes, up to parent attributes, or across to attributes from other
hierarchies.
For Freeform SQL reports, support for drilling is limited to attributes within
the personal Intelligent Cube. The personal Intelligent Cube includes all the
objects in the report definition, not just the ones you view on the report
template. While you can perform some drilling on Freeform SQL reports, the
options are minimal and largely restricted to project attributes.
For more information about drilling on Freeform SQL reports, see the
“Creating Freeform SQL Reports” lesson starting on page 33.
Some features that are part of the Report Data Options settings are not
supported for Freeform SQL reports. For example, you cannot change the
attribute or metric join type or create report limits since both of these
functions involve changes to the report SQL. Other settings like the
evaluation order, object aliases, and null value display are available for
Freeform SQL reports.
Administrative Functions
In addition to reporting functions, a variety of administrative functions that
affect report behavior also apply to Freeform SQL reports. Administrative
functions such as report caching, scheduling or subscribing to reports, job
prioritization, object-level security, security filters, and governing are
available for Freeform SQL reports.
Now that you understand the purpose of Freeform SQL reports, the benefits
of using them in your MicroStrategy project, and the MicroStrategy
functionality they support, you are ready to learn how to design and use
Freeform SQL reports.
Lesson Summary
In this lesson, you learned:
• Freeform SQL reports enable you to enter custom SQL to retrieve data
from a variety of data sources, including other relational databases,
Microsoft Excel spreadsheets, and text files.
• You can use Freeform SQL reports to access data stored in operational
tables or other data sources that are not optimized for OLAP analysis,
access data that is stored in relational database other than your primary
data warehouse, run stored procedures or other existing SQL routines,
tune the MicroStrategy SQL engine-related SQL, rapidly prototype
reports against new data that has not been included in your data
warehouse, or retrieve data from multiple data sources and combine it in
a single report container.
• In Freeform SQL report, you can create only percent to total and rank
shortcut metrics. You cannot define transformation shortcut metrics.
• In Freeform SQL reports, you cannot change the attribute or metric join
type. You also cannot create report limits. You can, however, change the
evaluation order, object aliases, and null value displays.
• You can change some report-level VLDB properties, however many of the
VLDB properties do not apply to Freeform SQL reports.
Lesson Description
This lesson describes the process of creating Freeform SQL reports and
implementing them in your MicroStrategy project.
In this lesson, you will learn about the steps involved in creating Freeform SQL
reports, including configuring Freeform SQL database instances and using the
Freeform SQL Editor. You will also learn how to work with managed objects, a
class of objects that includes the Freeform SQL objects you create within
Freeform SQL reports. Finally, you will learn about adding filter conditions to
Freeform SQL reports, drilling on Freeform SQL reports, and using Freeform
SQL reports in Report Services documents.
Lesson Objectives
After completing the topics in this lesson, you will be able to:
• Describe the steps involved in creating Freeform SQL reports. (Page 35)
• Configure a Freeform SQL database instance that you can use for Freeform
SQL reports. (Page 36)
• Create a Freeform SQL report using the Freeform SQL Editor. (Page 43)
• Describe the purpose of managed objects and work with them in the
context of Freeform SQL reports. (Page 55)
• Describe how you can use Freeform SQL reports in Report Services
documents. (Page 74)
Now that you understand the basic premise of using Freeform SQL reports,
you are ready to learn how to create them in MicroStrategy Developer.
3 Select the database instance that you want to use as a data source.
5 Map all of the columns in the SELECT clause of the SQL statement.
You will learn in detail about performing each of these steps throughout this
lesson.
Before you begin creating a Freeform SQL report, you have to be able to
connect to the data source that you want to use. You achieve this connectivity
by creating a database instance and configuring it for use by Freeform SQL
reports.
Ifconnection
you are using security features such as warehouse authentication or
mapping, different users may access the same data
warehouse using different DSNs or logins. However, even in these
cases, the project database instance is still associated with a default
DSN and login.
Although a project uses a single, primary database instance to access the data
warehouse, you can create any number of database instances that point to a
variety of data sources. You can then use these database instances for other
tasks such as importing data or creating data marts and Freeform SQL
reports.
Toappropriate
create and configure database instances, you must have the
administrative privileges. For more information on
database instances, see the MicroStrategy Administration:
Configuration and Security course.
IfFreeform
you plan to use your project database instance as the data source for
SQL reports, you do not need to manually configure it for
Freeform SQL reporting. The project database instance is
automatically configured for Freeform SQL reporting.
2 Under the project source, right-click the project in which you want to
create Freeform SQL reports and select Project Configuration.
The following image shows the available database instances in the Project
Configuration window:
Available Database Instances in Project Configuration Window
The Project Configuration window shows that six database instances are
available for Freeform SQL reporting, including the Customer Analysis
FFSQL database instance that is used in the examples in this lesson. Because
Tutorial Data is the project’s primary database instance, it is automatically
available for use with Freeform SQL reports. You have to manually configure
any other database instances that you create if you want to use them as data
sources for Freeform SQL reports.
You can configure as many database instances for Freeform SQL reporting as
needed. You need a database instance for each distinct data source that you
want to access using Freeform SQL reports. Any number of Freeform SQL
reports can share the same database instance if they all need to access the
same data source. After configuring the necessary Freeform SQL database
instances, you are ready to create the actual reports.
You create Freeform SQL reports using the Freeform SQL Editor, which
enables you to define your own custom SQL and map the columns in your
SQL to objects that you want to display on the report.
1 Open the Report Editor just as you would for creating a standard report.
3 In the Source list, select the database instance you want to use for
Freeform SQL reporting.
5 Click OK.
The Freeform SQL Editor is available to users who have the “Define
freeform SQL report” and “Create schema objects” privileges.
The following image shows the New Grid window with the Freeform SQL
option selected:
Use Freeform SQL Editor Option
Selecting the Create Freeform SQL report option when you create a new
report enables you to access the Freeform SQL Editor. The following image
shows the Freeform SQL Editor:
Freeform SQL Editor
• SQL Statement Pane—Enables you to enter your own custom SQL that
you want to execute against the selected database instance to retrieve data
for the Freeform SQL report.
• Mapping Pane—Enables you to map the columns that are returned in the
SELECT clause of your SQL statement to objects that you want to display
in the report.
• Object Browser—Enables you to browse and select objects that you want
to map as columns in the Freeform SQL report. You can access existing
project attributes and objects that are specifically created for Freeform
SQL reports. You can also create new Freeform SQL objects.
You will learn more about using each of these components later in this lesson.
The procedure that is described in the previous topic enables you to access
the Freeform SQL Editor when you are creating a new Freeform SQL report.
However, you can also access the Freeform SQL Editor for existing Freeform
SQL reports.
To access the Freeform SQL Editor for an existing Freeform SQL report:
2 In the Report Editor, from the Data menu, select Freeform SQL
Definition.
This option enables you to access and modify the Freeform SQL definition for
existing Freeform SQL reports.
Now that you know how to access the Freeform SQL Editor, you are ready to
learn more about using it to create Freeform SQL reports.
Within the Freeform SQL Editor, you define a Freeform SQL report by
completing the following steps:
1 Select the database instance that you want to use as a data source.
3 Map all of the columns in the SELECT clause of the SQL statement.
1 In the Freeform SQL Editor, in the Database Instance list, select the
database instance that you want to use.
This list displays only database instances that you have configured
as Freeform SQL reporting database instances for the project.
The following image shows the Customer Analysis FFSQL database instance
selected as the data source for a Freeform SQL report:
Selected Freeform SQL Database Instance
The custom SQL for this report will execute against the database that is
associated with the Customer Analysis FFSQL database instance.
When defining the SQL statement for a Freeform SQL report, you should be
aware of the following:
• You can only use a single SELECT clause to retrieve the data that you
want to display in the report.
Ifstored
you are running multiple passes of SQL (for example, executing a
procedure), the last SELECT clause is the one that is used to
retrieve the data for the report.
Atdatabase.
the ODBC level, all the SQL passes are sent at one time to the
Semicolon-separated SQL is not part of the ANSI SQL
standard. Therefore, you cannot use multipass SQL directly in the
Freeform SQL Editor.
• You can use derived table expressions and common table expressions in
your SQL statement to create subqueries.
You need to check the data source that you are using to verify
whether it supports derived table and common table expressions.
Some databases do not support both types of expressions.
• You can use pre- and post-SQL statements (report-level VLDB properties)
in conjunction with a Freeform SQL report.
1 In the Freeform SQL Editor, in the SQL Statement pane, enter the SQL
statement that you want to use for the report.
When you type the SQL statement, you can press Control + Tab to
indent lines of SQL as needed. This format makes the finished SQL
statement easier to read.
The following image shows the SQL statement for the Freeform SQL report:
SQL Statement for Freeform SQL Report
• Filters the data by limiting the result set to customers whose revenue is
greater than or equal to $5,000
Given the custom SQL, the final report will display the customers who have
purchased $5,000 or more in products from the company. For each
customer, the report will also display their level of education.
You can map columns to existing attributes. You can also create new attribute
and metric objects within the Freeform SQL Editor and map columns to
these objects. Whenever you create a new object (attribute or metric) within a
Freeform SQL report, you are creating a Freeform SQL object. You can use
these objects in any Freeform SQL report that you create.
For each attribute in a Freeform SQL report, you must map a column
to the ID form.
You can map fact columns in your SQL statement to any of the following:
To map attribute columns for a Freeform SQL report using existing project
attributes:
2 Click the + icon beside the attribute to view its attribute forms.
3 Drag the attribute form that you want to use to the Mapping pane.
To map attribute columns for a Freeform SQL report using existing Freeform
SQL attributes:
When you first open the Freeform SQL Editor, this folder is
displayed by default. This folder contains all Freeform SQL objects
that have been created in the project (both attributes and metrics).
2 In the Freeform Objects folder, browse to the attribute that you want to
use.
3 Click the + icon beside the attribute to view its attribute forms.
4 Drag the attribute form that you want to use to the Mapping pane.
To map attribute columns for a Freeform SQL report by creating new Freeform
SQL attributes:
Ifproject
you enter an attribute name that is identical to an existing
attribute, when you save the Freeform SQL definition,
MicroStrategy Developer automatically maps the column to the
existing project attribute rather than creating a new Freeform SQL
attribute.
4 In the Form drop-down box, select the form that you want to map.
You create and map forms one at a time. You need to map the ID
form and any other attribute forms that are included in the
SELECT clause.
To map fact columns for a Freeform SQL report using existing Freeform SQL
metrics:
2 In the Freeform Objects folder, drag the metric that you want to use to the
Mapping pane.
You can also double-click the metric to add it to the Mapping pane.
To map fact columns for a Freeform SQL report by creating new Freeform SQL
metrics:
Remember that you must map columns in the order in which they
appear in the SELECT clause. If you need to change the order of an
object in the Mapping pane, right-click the object and select Move Up
or Move Down. If you want to remove an object from the column
mapping, right-click the object and select Remove.
The following image shows the column mapping for the Freeform SQL
report:
Column Mapping for Freeform SQL Report
The SELECT clause of the SQL statement contains the customer ID and
name, customer education ID and description, and the Revenue fact, which is
aggregated. Therefore, you have to map the following columns for the
Freeform SQL definition:
• Revenue
In this example, you map the attribute columns by creating new Freeform
SQL attributes. There is an existing Freeform SQL metric for Revenue, so you
can use this object to map the metric column. Notice that the objects are
mapped in the same order as the columns appear in the SELECT clause. The
template for the report will display the Customer FFSQL and Customer
Education attributes, along with the Revenue metric.
Below are the benefits of mapping attribute columns in the SQL statement
pane to existing project attributes:
• You can apply security filters that are based on project attributes to
Freeform SQL reports.
Closing the Freeform SQL Editor returns you to the Report Editor in Design
View. The following image shows the Report Editor in Design View for the
Freeform SQL report:
Freeform SQL Report - Design View
You can use the Design View of the Report Editor to review the template
layout and make any desired changes. By default, the attributes that you have
defined are in the rows of the report, and the metrics are in the columns of
the report. The attributes and metrics display on the template in the order
that you defined them in the Freeform SQL Editor. Therefore, the report
template contains the Customer FFSQL and Customer Education attribute in
the rows and the Revenue metric in the column.
Also, notice that the Report Objects window contains both the ID and
description forms for the two attributes since both forms are retrieved by the
SQL statement. However, by default, the template displays only the
description forms.
You can make any necessary changes to the template layout before saving the
report, including common manipulations such as the following:
• Adding objects to the grid from the Report Objects window or removing
objects from the grid to the Report Objects window
• Formatting metrics
Byvalues
default, metrics display as fixed numbers. If you want metric
to display as currency, percentages, or other types of
formats, you can make these changes in Design View.
After you have made all the desired changes to the report, you need to save
the report before you can run it. If you try to run a Freeform SQL report
before saving it, you are prompted to save the report first. You save Freeform
SQL reports just as you would standard reports.
IfSQLyoureport,
modify the Freeform SQL definition of an existing Freeform
you are also prompted to save the changes before
executing the report.
After saving the Freeform SQL report, you can execute it. You can execute
Freeform SQL reports from Design View just as you would standard reports.
The following image shows the first part of the result set for the Freeform
SQL report:
Result Set for Freeform SQL Report
Inas currency
the image above, the Revenue metric has been formatted to display
using two decimal places.
Notice that the report result displays customer names, their education levels,
and the revenue associated with each customer. However, the report result
displays only those customers who have purchased $5,000 or more in
products.
If you switch to the SQL View for the report, you can see that the custom SQL
statement you created was used to retrieve the report data:
Freeform SQL Report - SQL View
Notice that the report executed against the Customer Analysis FFSQL
database instance that you selected in the Freeform SQL report definition.
Also, the SQL pass matches the custom SQL statement that you defined for
the report. This report is an example of using custom SQL to create a simple
Freeform SQL report. For more information about using more advanced SQL
to create Freeform SQL reports, see the “Advanced Topics for Freeform SQL
Reports” lesson starting on page 127.
Managed Objects
Now that you know how to create a basic Freeform SQL report, you need to
understand the role of managed objects in Freeform SQL reports.
IfCube
you integrate MicroStrategy with SAP BW when you create an OLAP
report, the objects you create to describe the cube are also
created as managed objects. For more information, see the MDX Cube
Reporting Guide.
Because a single Freeform SQL report can result in many new objects as you
map columns, the use of managed objects prevents you from having to
individually save each attribute or metric that you create.
The following image shows the definition of the Freeform SQL report created
earlier in this lesson:
Freeform SQL Report Definition
In this image, the Object Browser is displaying the available Freeform SQL
objects. The Customer FFSQL and Customer Education attributes were
created specifically for this Freeform SQL report. These two attributes as well
as all the existing Freeform SQL attributes and metrics are managed objects.
2 In the Freeform Objects folder, right-click the desired object and select
Properties.
Alternatively, you can also view managed objects by using the search function
in MicroStrategy Developer. This method enables you to view all managed
objects in a project.
2 In the Search for Objects window, on the Tools menu, select Options.
4 If you want your search to return only managed objects, select the
Display Managed Objects Only check box.
5 Click OK.
6 In the Search for Objects window, enter the desired search parameters.
Insincethemanaged
Look in box, you should choose to search the entire project
objects are stored in a system folder within the
project. Otherwise, your search will not return any results.
After the managed objects are displayed in the Search for Objects
window, you can use the right-click menu to perform a variety of
functions. You can edit, rename, translate, export to text, and delete
managed objects; create shortcuts to managed objects; search
dependents or components of managed objects; and view managed
object properties. You will learn more about editing and deleting
managed objects later in this lesson.
The following image shows the search options for displaying managed
objects:
Search Options for Displaying Managed Objects
By default, these two options are not enabled when you open the Search for
Objects window. Therefore, you have to select these options each time you
perform a search for managed objects.
The following image shows the first part of a search result that displays the
managed objects in a project:
Search Result for Managed Objects
Notice that the search result includes all the existing Freeform SQL attributes
and metrics, including the newly created Customer FFSQL and Customer
Education attributes. Rather than displaying a location for the objects, the
Path field shows that each of these objects is “Managed by the system”.
In the Search for Objects window, in the search result list, right-click the
attribute or metric that you want to edit and select Edit.
The following image shows the Attribute Editor for a Freeform SQL attribute:
Attribute Editor for Freeform SQL Attribute
Notice that the form expression indicates that the Customer Education
attribute maps to a Freeform SQL report. Instead of having source tables,
Customer Education Analysis is listed as a source report. This report is the
Freeform SQL report to which the Customer Education attribute is mapped.
You cannot edit the mapping of existing form expressions for a Freeform SQL
attribute. However, you can use the Attribute Editor to modify the attribute
form names and formats or to change the default report display forms.
The Children and Parent tabs do not apply to Freeform SQL attributes.
If you map a project attribute to columns in a Freeform SQL report, you
simply add Freeform SQL attribute form expressions to the existing attribute.
The Attribute Editor then displays both the standard and Freeform SQL
attribute form expressions. As with Freeform SQL attributes, you cannot edit
the Freeform SQL expressions of project attributes.
You cannot edit any part of the definition of a Freeform SQL metric.
However, you can use the Metric Editor to format how the metric values
display and change the subtotaling and dynamic aggregation behavior of the
metric, including disabling subtotals.
The following image shows the Metric Editor for a Freeform SQL metric:
Metric Editor for Freeform SQL Metric
The image above displays the definition for the Freeform SQL
Revenue metric, not the Revenue project metric.
Notice that the Revenue metric definition is null because it simply points to a
fact column in the Freeform SQL statement. The Freeform SQL statement
itself defines how to aggregate the data, rather than the metric definition.
When you edit Freeform SQL attributes or metrics from the Report Editor,
you need to re-execute the report to display any changes you made. When
you edit Freeform SQL attributes or metrics from the Search for Objects
window, you should see the changes the next time you run a report that uses
the objects that you modified.
1 Perform a search for the managed objects that you want to delete.
2 In the Search for Objects window, in the search result list, right-click the
attribute or metric that you want to delete and select Delete.
Deleting managed objects from the Search for Objects window enables you to
delete individual managed objects from a project. If you delete a Freeform
SQL report, this option is useful for deleting managed objects that were used
only in that report.
However, you may also have a scenario in which you create a database
instance that you use as a data source for Freeform SQL reports in a project.
At some point in time, you may no longer need any of the Freeform SQL
reports that use this database instance. You can delete the Freeform SQL
reports from the project, but you may also want to delete all of the managed
objects that were used in those reports. Because deleting these managed
objects one by one would be time consuming, you have the option to delete all
of the unused managed objects at the same time.
To delete all of the unused managed objects associated with a Freeform SQL
database instance:
This window warns you that you are removing the Freeform SQL
schema object that is associated with the database instance.
7 If you have editors or search windows open, you will see a warning
message to close them. In the message window, click Yes to enable
MicroStrategy Developer to close them, or click No and close them
manually.
This process may take a few minutes. This option deletes unused
managed objects that are associated solely with the Freeform SQL
database instances you removed from the project.
In a standard report, the report filter is the object that you use to specify the
conditions that data must meet to be included in the result set. With standard
reports, you can create report filters within the definition of a report, or you
can include existing filters in a report.
Freeform SQL reports work differently. In the Freeform SQL Editor, you
cannot drag existing filters into the report definition. However, you can add
filtering conditions to a Freeform SQL report within the context of the SQL
statement. You can add conditions in the WHERE clause or HAVING clause
to define the data that you want to include in the result set.
For example, the following image shows the definition of the Freeform SQL
report created earlier in this lesson:
Freeform SQL Report Definition with Filter in HAVING Clause
This report contains a HAVING clause in the SQL statement with the
following condition:
Filters can also appear in the WHERE clause. For example, the following
image shows the definition of a Freeform SQL report that contains filtering
conditions in the WHERE clause:
Freeform SQL Report Definition with Filter in WHERE Clause
These reports are both examples of using static filters in the SQL. You can
also use prompts in a Freeform SQL statement to create dynamic filters. For
more information about including prompts in Freeform SQL reports, see the
“Prompts in Freeform SQL Reports” lesson starting on page 97.
Drilling enables you to view data at levels other than that of the original
report. When you are working with standard reports, you can easily drill from
one attribute level to another.
However, drilling is more limited when working with Freeform SQL reports.
You can drill only to attributes contained within the personal Intelligent
Cube. The personal Intelligent Cube contains all the attributes in the report
definition, not just the ones you view on the report template. Drilling to
attributes outside the personal Intelligent Cube would require the SQL
Engine to generate additional SQL. Since Freeform SQL reports use custom
SQL rather than Engine-generated SQL, this option is not available.
You can drill from a project attribute or a Freeform SQL attribute to a project
attribute or a Freeform SQL attribute that is in the Report Objects window
but not in the template.
The following image shows the menu options that are available when you
right-click the Customer City FFSQL attribute:
Drilling Between Freeform SQL Attributes
Notice that the right-click menu displays the Drill option. Drilling from the
Customer City FFSQL to the Customer FFSQL attribute is possible although
no relationship exists between these two attributes. This is because the
Customer FFSQL attribute is in the Report Objects window, which makes it a
part of the personal Intelligent Cube of the report.
The following image shows the same Freeform SQL report with some
modifications to the attributes on the report:
Freeform SQL Report - Modified Drilling Example
The following image shows the menu options that are available when you
right-click the Customer City attribute:
Drilling on Project Attributes
Drilling is available on the Customer City project attribute. However, you are
limited to drilling to objects contained within the personal Intelligent Cube.
You can drill from Customer City to Customer, Customer Gender FFSQL and
Month attributes because these three attributes are in the Report Objects
window, which makes them part of the personal Intelligent Cube for the
report.
You can modify the report to place the Customer Gender FFSQL attribute on
the template and remove the Customer City attribute from the template. The
following image shows the right-click menu options that are available when
you right-click the Customer Gender FFSQL attribute:
Drilling on Freeform SQL Attributes
You can drill from the Customer Gender FFSQL attribute to any attributes
that are part of the personal Intelligent Cube. In this example, you can drill
from Customer Gender FFSQL to the Customer City, Customer, or Month
attributes.
You can use any Freeform SQL report that you create to build a Report
Services document. Within the context of a document, you can integrate data
from a Freeform SQL report with data from standard reports or other data
sources. To join data from different data sources, the reports or datasets in a
document must share a common attribute. For example, consider the
following document definition:
Using Freeform SQL Reports in Documents
However, even though this document uses three different reports that
retrieve data from three different data sources, all three reports contain the
Region attribute. The standard report contains the Region project attribute,
and each of the Freeform SQL reports contains a column that maps to the
Region project attribute. Therefore, Region is the common attribute that is
used to join the data from each report and generate the document results.
Lesson Summary
In this lesson, you learned:
• You need to configure a database instance for each data source to access
data for your Freeform SQL report.
• Freeform SQL Editor enables you to define your own custom SQL and
map the columns in your SQL to objects that you want to display on the
report.
• You cannot use multipass SQL when defining the SQL statement for a
Freeform SQL report.
• You can use derived table expressions, common table expressions, and
stored procedures in your SQL Statement.
• You must map each columns in the same order that is referenced in the
Select clause of the SQL Statement. You can map columns to existing
attributes in the project.
• Any new object that you create within a Freeform SQL report is created as
a managed Freeform SQL object and these objects can only be viewed
using the Freeform SQL Editor.
• You can add filtering conditions in the WHERE clause or HAVING clause
of the SQL statement. You cannot drag any existing filter to the report
definition of a Freeform SQL report.
• You can use Freeform SQL reports to build a Report Services document.
Exercises
You should complete the following exercises using the MicroStrategy Tutorial
project, which is found in the MicroStrategy Analytics Modules project
source.
Overview
Before beginning the exercises, you need to create a new subfolder named
Freeform SQL Exercises inside the My Personal Objects\My Reports folder.
You will save all of your work for the exercises in this course to this folder.
Detailed Instructions
3 In the Object Viewer, right-click an empty area, point to New, and select
Folder.
Overview
In this exercise, you will create a new database instance and configure it for
Freeform SQL reporting. This database instance should point to the
FFSQL_CUST_WH DSN and should use the sa database login. You can name
the database connection and database instance Customer Analysis FFSQL.
After you have created this database instance, configure it for use by
Freeform SQL reports.
Detailed Instructions
6 Click New.
10 Click OK.
12 Click OK.
Overview
In this exercise, you will create a Freeform SQL report using the Customer
Analysis FFSQL database instance. This report should contain the following
attributes: Customer FFSQL, Month FFSQL, and Product. It should also
contain the Revenue and Profit metrics. The Profit metric is defined as
(Revenue - Cost). The report should contain only data for Q4 2011.
You only need to display the attribute description forms in the result
set, although you should include both the ID and description forms in
the report SQL.
Finally, you need to format both metrics to display as currency with two
decimal places. Save the report in the Freeform SQL Exercises folder as Q4
2011 Customer Purchase Analysis.
Run the report. The first part of the result set should look like the following:
In creating this report, you will use tables from the FFSQL_CUST_WH
database. You can reference the physical schema for this warehouse in
Appendix A, Customer Analysis Schema.
Detailed Instructions
5 Click OK.
8 In the Exercises SQL Microsoft Word document, copy the SQL labeled as
Q4 2011 Customer Purchase Analysis and paste it into the SQL
Statement pane of the Freeform SQL Editor. The SQL looks like the
following:
9 Keep the Exercises SQL Microsoft Word document open as you will use it
later in the exercises.
11 In the Mapping pane, for Column 1, in the Object box, type Customer
FFSQL as the attribute name. Leave the Form as ID.
13 In the Mapping pane, for Column 2, in the Object box, type Customer
FFSQL as the attribute name.
16 In the Mapping pane, for Column 3, in the Object box, type Month
FFSQL as the attribute name. Leave the Form as ID.
18 In the Mapping pane, for Column 4, in the Object box, type Month
FFSQL as the attribute name.
21 In the Mapping pane, for Column 5, in the Object box, type Product as
the attribute name. Leave the Form as ID.
23 In the Mapping pane, for Column 6, in the Object box, type Product as
the attribute name.
26 Double-click Profit.
Your column order needs to match the above image as you must
map the columns in the same order as they appear in the SQL
statement. You can drag and drop the columns to change the order
or right-click the columns and use the Move Up or Move Down
options.
27 Click OK.
29 In the Format Cells window, on the Number tab, under Category, select
Currency.
30 Click OK.
33 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
34 Keep the report open as you will use it in the next exercise.
Overview
In this exercise, you will modify the Q4 2011 Customer Purchase Analysis
Freeform SQL report that you created in the previous exercise. You can
perform many types of report manipulations on Freeform SQL reports just as
you can with standard reports. You should perform the following
manipulations on the Q4 2011 Customer Purchase Analysis report:
You can use the default settings for the Total subtotal.
• Change the autostyle for the report to Finance
• Change the background color for the row values to Light Green
• Sort the report by the Revenue metric in Descending order and sort the
metric hierarchically using the Total subtotal
Save the report in the Freeform SQL Exercises folder as Formatted Q4 2011
Customer Purchase Analysis.
Detailed Instructions
Add subtotals
4 Click OK.
8 In the Grid Options window, on the General tab, under Banding, select No
banding.
9 Click OK.
14 Click OK.
23 Click OK.
24 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
Overview
In this exercise, you will create a second database instance and configure it
for Freeform SQL reporting. This database instance should point to the
FFSQL_EMP_WH DSN and should use the sa database login. Nsame the
database connection and database instance Employee Analysis FFSQL. After
you have created this database instance, configure it for use by Freeform SQL
reports.
Detailed Instructions
6 Click New.
10 Click OK.
12 Click OK.
Overview
In this exercise, you will create a Freeform SQL report using the Employee
Analysis FFSQL database instance. This report should contain the following
attributes: Employee Location and Employee FFSQL. It should also contain
an Average Performance Score metric. You need to format this metric to
display as a fixed number with two decimal places.
You only need to display the attribute description forms in the result
set, although you should include both the ID and description forms in
the report SQL.
Run the report. The first part of the result set should look like the following:
In creating this report, you will use tables from the FFSQL_EMP_WH
database. You can reference the physical schema for this warehouse in
Appendix B, Employee Analysis Schema.
Detailed Instructions
4 With the Create Freeform SQL report radio button selected, click OK.
5 In the Exercises SQL Microsoft Word document, copy the SQL labeled as
Employee Performance Analysis and paste it into the SQL Statement
pane of the Freeform SQL Editor. The SQL looks like the following:
6 Keep the Exercises SQL Microsoft Word document open as you will use it
later in the exercises.
8 In the Mapping pane, for Column 1, in the Object box, type Employee
Location as the attribute name.
10 In the Mapping pane, for Column 2, in the Object box, type Employee
Location as the attribute name.
13 In the Mapping pane, for Column 3, in the Object box, type Employee
FFSQL as the attribute name.
15 In the Mapping pane, for Column 4, in the Object box, type Employee
FFSQL as the attribute name.
18 In the Mapping pane, for Column 5, in the Object box, type Average
Performance Score as the metric name.
Your column order needs to match the above image as you must
map the columns in the same order as they appear in the SQL
statement. You can drag and drop the columns to change the order
or right-click the columns and use the Move Up or Move Down
options.
19 Click OK.
23 Click OK.
26 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
27 Keep the report open as you will use it in the next exercise.
Overview
In this exercise, you will modify the filtering conditions of the Employee
Performance Analysis Freeform SQL report that you created in the
previous exercise. The original report does not have any filtering conditions.
You need to modify the SQL statement for the Employee Performance
Analysis report to include only employees in the East and West regions
who have an average performance score of 4 or above.
Before executing the report, save the report in the Freeform SQL Exercises
folder as Highest-Performing Employees for East and West Regions.
Run the report. After you modify the filtering conditions, the result set should
look like the following:
In modifying the filtering conditions for this report, you will use tables from
the FFSQL_EMP_WH database. You can reference the physical schema for
this warehouse in Appendix B, Employee Analysis Schema.
When you finish modifying the report, answer the two follow-up questions at
the end of the detailed instructions for this exercise.
Detailed Instructions
3 In the Freeform SQL Editor, in the SQL Statement pane, delete the
original SQL statement.
4 In the Exercises SQL Microsoft Word document, copy the SQL labeled as
Highest Performing Employees for East and West Regions and paste
it into the SQL Statement pane of the Freeform SQL Editor. The SQL
looks like the following:
Notice that the SQL now contains two filter conditions. The
condition in the WHERE clause limits the result set to two regions
(East and West). The condition in the HAVING clause limits the
result set to display only employees in these two regions with an
average performance score of 4 or higher.
7 In the Report Editor, in Design View, save the report in the Freeform SQL
Exercises folder as Highest-Performing Employees for East and West
Regions.
9 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
10 Answer the follow-up questions about this report. After you have
answered the questions, close the report.
Follow-up Questions
1 Can you drill on the Employee FFSQL attribute in this report? Why or
why not?
_______________________________________
_______________________________________
_______________________________________
_______________________________________
_______________________________________
_______________________________________
_______________________________________
_______________________________________
1 You cannot drill on the Employee FFSQL attribute because the only other
attribute in the Report Objects window (Employee Location) is already on
the report template.
Lesson Description
This lesson describes how to use prompts in Freeform SQL reports to enable
end users to dynamically select report content.
In this lesson, you will learn about the types of prompts that are supported for
Freeform SQL reports. Then, you will learn how to add new prompts or insert
existing prompts into Freeform SQL reports and how to configure prompts as
optional.
Lesson Objectives
After completing the topics in this lesson, you will be able to:
• Describe the types of prompts that you can use in Freeform SQL reports.
(Page 99)
• Add new prompts and insert existing prompts into Freeform SQL reports.
Configure prompts as optional. (Page 100)
Prompts are MicroStrategy objects that you can use in reports to enable end
users to select the content of a report at run time. Freeform SQL reports
support the following two types of prompts:
When you create a prompt as part of a Freeform SQL report, it is saved in the
metadata as a normal prompt object, not a managed object. The remainder of
this lesson describes how to incorporate element list and value prompts into
Freeform SQL reports.
You have two options for including prompts in Freeform SQL reports:
• Add New Prompt—This option opens the Prompt Generation Wizard and
enables you to create a new element list or value prompt.
You can access both of these options on the Edit menu in the Freeform SQL
Editor, which is shown in the following image:
Edit Menu - Prompt Options
You can also access these options on the right-click menu if you
right-click inside the SQL Statement pane.
100 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
1 In the Freeform SQL Editor, in the SQL Statement pane, place the cursor
at the location where you want to include the prompt.
OR
4 Click Next.
When you finish creating the prompt, it is inserted into the SQL statement at
the location where you positioned the cursor. Alternatively, if you selected
part of the SQL before opening the Prompt Generation Wizard, the prompt
replaces the selected SQL. Prompts display in the SQL statement in pink text.
If a prompt name contains spaces, it is enclosed in brackets. For example, a
prompt named Select Year would display as [Select Year].
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 101
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
1 In the Freeform SQL Editor, in the SQL Statement pane, place the cursor
at the location where you want to include the prompt.
This action opens a window that enables you to browse for and
select an existing prompt in the project.
3 In the Select a Prompt window, browse to and select the prompt that you
want to use in the report.
4 Click Open.
You cannot type the name of an existing prompt directly in the SQL
statement of a Freeform SQL report.
Again, the prompt is either inserted at your cursor position, or it replaces any
SQL that you have selected. Just as with new prompts that you create in the
Freeform SQL Editor, existing prompts display in pink text and are enclosed
in brackets if the prompt name contains spaces.
102 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
This report retrieves revenue data for all customers of the selected customer
gender. The WHERE clause contains a prompt that enables you to select the
customer gender that you want to include in the report. You can only create
element list prompts based on project attributes, so in this example, the
CUST_GENDER_ID column is mapped to the Customer Gender project
attribute. The other columns are all mapped to Freeform SQL attributes or
metrics.
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 103
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
When you use an element list prompt with an IN operator, you have to
manually type parentheses around the name of the prompt in the SQL
statement to ensure the appropriate syntax. The parentheses are not
needed in all cases and, in some circumstances, can cause syntax
errors. Therefore, to make prompt usage more flexible in Freeform
SQL reports, they are not automatically inserted.
If you run this report, the following image shows the prompt that is displayed
to you:
Customer Gender Element List Prompt
104 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
Notice that the prompt enables you to choose from the customer gender
values that are stored in the Tutorial database. You can select one or more
customer genders. If you select male as your prompt answer, the first part of
the result set looks like the following:
Result Set for Freeform SQL Report with Customer Gender Element List
Prompt.
Inas currency
the image above, the Revenue metric has been formatted to display
using two decimal places.
Notice that the result set includes only male customers. As with any
prompted report, if you save it, you can choose to save it as static or
prompted. You can also choose whether you want to retain your prompt
answers as the default answers the next time you run the report.
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 105
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
The following image shows the SQL View for this report:
Freeform SQL Report with Customer Gender Element List Prompt - SQL
View
When the report executes, the MicroStrategy Engine converts the elements
that you select into their corresponding IDs. In this example, the SQL
statement uses the IN operator, and it includes the customer gender that you
selected.
106 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
You can also use other operators with element list prompts such as =, >, <,
and so forth. With these operators, you do not need to insert parentheses
around the prompt name as you do with the IN operator. However, unlike the
IN operator, which can take multiple prompt answers, these other operators
only allow for a single answer. To ensure that end users do not select more
answers than an operator allows, you need to define the prompt so that it
limits the number of answers to one.
This report retrieves revenue data for all customers in a selected customer
city. The WHERE clause contains a prompt that enables you to enter the
description of the customer city that you want to include in the report. With
value prompts, you are not limited to project attributes. Therefore, in this
example, all the columns are mapped to Freeform SQL attributes or metrics.
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 107
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
Date, number, and big decimal prompts are automatically formatted to the
standards of the database platform against which you execute the report.
However, when you use a text value prompt, you have to manually type single
quotes around the name of the prompt in the SQL statement to ensure the
appropriate syntax for a text constant.
You do not have to add single quotes around text value prompts if you
are prompting for an object name as part of a SQL command. For
example, you could have a SQL statement like the following:
In this case, you are using a text value prompt in the FROM clause of a
Freeform SQL report to select the name of the table from which you
want to retrieve data.
Ifenter
you are prompting on which table to retrieve data from, you should
the most commonly used or most appropriate table as the
default value of the prompt.
If you run this report, the following image shows the prompt that is displayed
to you:
Customer City Value Prompt
108 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
Notice that the prompt enables you to enter the description for any customer
city that is stored in the FFSQL_CUST_WH database. You can enter a value
for only one city. If you enter Seattle as your prompt answer, the first part of
the result set looks like the following:
Result Set for Freeform SQL Report with Customer City Value Prompt
Inas currency
the image above, the Revenue metric has been formatted to display
using two decimal places.
Notice that the result set includes only customers in Seattle. As with any
prompted report, if you save it, you can choose to save it as static or
prompted. You can also choose whether you want to retain your prompt
answer as the default answer the next time you run the report.
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 109
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
The following image shows the SQL View for this report:
Freeform SQL Report with Customer City Value Prompt - SQL View
When the report executes, the MicroStrategy Engine inserts the value that
you entered in place of the prompt. In this example, the SQL statement uses
the = operator, and it includes the city that you entered. As with element list
prompts, you can also use other operators such as >, <, and so forth.
110 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
If you use optional prompts in a Freeform SQL report, you must make the
prompt and all SQL related to it prompt dependent. Otherwise, if end users
choose not to answer an optional prompt, the report fails since part of the
required SQL is missing.
For example, you could modify the Customer Gender element list prompt
that was used earlier in this lesson to make it an optional prompt. You make
prompts optional in the Prompt Generation Wizard by clearing the Prompt
answer required check box, which is shown in the following image:
Optional Customer Gender Element List Prompt
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 111
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
Now when you run the Freeform SQL report that uses this prompt with the
original SQL statement and do not select a customer gender in response to
the prompt, the report fails as follows:
Failed Report for Optional Customer Gender Element List Prompt
112 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
The following image shows the SQL View for this report:
Failed Report for Optional Customer Gender Element List Prompt - SQL
View
Notice that the WHERE clause is incomplete because the SQL that is related
to the prompt is still part of the SQL statement. “CUST_GENDER_ID IN ()”
is part of the report SQL, but because you did not answer the prompt, there is
no value for the IN operator. This incomplete SQL causes the report to fail.
To account for the optional prompt, you need to make the prompt and all
SQL related to it (in this case, the condition in the WHERE clause) prompt
dependent.
1 In the Freeform SQL Editor, in the SQL Statement pane, select the SQL
that you want to make prompt dependent.
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 113
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
When you make SQL prompt dependent, it displays in pink text as shown in
the following image:
Prompt-dependent SQL
114 Creating a Freeform SQL Report with Prompts © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3
Now when you run the report and do not select a customer gender in
response to the prompt, the report executes and returns data for both the
customer genders in the database for which revenue data exists.
The following image shows the SQL View for the report:
Freeform SQL Report with Prompt-dependent SQL for Optional Customer
Gender Element List Prompt - SQL View
Notice that the prompt and all of the SQL related to it are removed from the
SQL statement so that the report can execute.
© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 115
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials
Lesson Summary
In this lesson, you learned:
• Freeform SQL reports support element list prompts and value prompts.
• You can create element list prompts based on project attributes only.
• Value prompts enable you to enter a date, numeric, text or big decimal
value. When you use text value prompt, you have to manually type single
quotes around the name of the prompt in the SQL statement.
Exercises
You should complete the following exercises using the MicroStrategy Tutorial
project, which is found in the MicroStrategy Analytics Modules project
source.
Overview
In this exercise, you will create a Freeform SQL report using the Customer
Analysis FFSQL database instance. This report should contain the following
attributes: Education Level and Customer FFSQL. It should also contain
the Revenue metric. You need to format this metric to display as currency
with two decimal places. You will then create a required element list prompt
on the Education Level project attribute and add it to the WHERE clause of
the SQL statement of the report. When you create the prompt, save it as
Choose Customer Education Level in the Freeform SQL Exercises folder.
You only need to display the attribute description forms in the result
set, although you should include both the ID and description forms in
the report SQL.
Save the report in the Freeform SQL Exercises folder as Customer Purchase
Analysis for Selected Customer Education Level.
Run the report and select Graduate as the prompt answer. The first part of
the result set should look like the following:
In creating this report, you will use tables from the FFSQL_CUST_WH
database. You can reference the physical schema for this warehouse in
Appendix A, Customer Analysis Schema.
Detailed Instructions
4 With the Create Freeform SQL report radio button selected, click OK.
7 In the Exercises SQL Microsoft Word document, copy the SQL labeled
Customer Purchase Analysis for Selected Customer Education
Level and paste it into the SQL Statement pane of the Freeform SQL
Editor. The SQL looks like the following:
Your column order needs to match the above image as you must
map the columns in the same order as they appear in the SQL
statement. You can drag the columns to change the order or
right-click the columns and use the Move Up or Move Down
options.
17 In the Freeform SQL Editor, in the SQL Statement pane, in the WHERE
clause, highlight <insert prompt>.
20 Click Next.
22 Click Next.
24 Under Display properties, in the Title box, enter a title for the prompt.
27 Click Finish.
29 In the Object name box, type Choose Customer Education Level as the
prompt name.
30 Click Save.
The prompt name replaces the <insert prompt> text in the SQL
statement for the report.
31 Type parentheses around the brackets that surround the prompt name.
The prompt name and the brackets that surround it should display
in pink text.
32 Click OK.
34 In the Format Cells window, on the Number tab, under Category, select
Currency.
35 Click OK.
39 Click Finish.
40 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
Overview
In this exercise, you will create an optional numeric value prompt. You will
then add a HAVING clause that uses this prompt to the SQL statement for
the Employee Performance Analysis report that you created as part of the
exercises in the previous lesson. When you create the prompt, save it as
Choose a Score Value in the Freeform SQL Exercises folder.
After you have made these changes to the report, save the report in the
Freeform SQL Exercises folder as Prompted Employee Performance
Analysis.
Re-execute the report using the Re-prompt option and do not select an
answer for the prompt. The first part of the result set should look like the
following:
In creating this report, you will use tables from the FFSQL_EMP_WH
database. You can reference the physical schema for this warehouse in
Appendix B, Employee Analysis Schema.
Detailed Instructions
Open the Freeform SQL report in Design View
2 In the Report Editor, in Design View, on the Data menu, select Freeform
SQL Definition.
3 In the Freeform SQL Editor, in the SQL Statement pane, position the
cursor at the end of the GROUP BY clause and press Enter.
4 Type Having.
10 Click Next.
12 Click Next.
13 Under Display properties, in the Title box, enter a title for the prompt.
16 Click Next.
19 In the Object name box, type Choose a Score Value as the prompt
name.
20 Click Save.
This window reminds you that you need to make the SQL prompt
dependent because the prompt you are inserting is an optional
prompt. After you click OK, the prompt name is inserted at the end
of the HAVING clause.
24 Click OK.
28 Click Finish.
29 Compare your results to the first expected report in the Overview section
at the beginning of this exercise.
30 Click the Re-prompt report toolbar button to re-execute the report and
display the prompt again. This button is indicated by the following icon:
31 When the prompt displays, clear your previous prompt answer and do not
enter another value.
32 Click Finish.
Lesson Description
This lesson describes how to create more advanced Freeform SQL reports.
In this lesson, you will learn about using derived and common table
expressions, stored procedures, and non-relational data sources with Freeform
SQL reports.
Lesson Objectives
After completing the topics in this lesson, you will be able to:
• Define derived and common table expressions and create Freeform SQL
reports that use derived and common table expressions. (Page 129)
• Create Freeform SQL reports that use stored procedures. (Page 135)
• Create Freeform SQL reports using Microsoft Excel files and text files.
(Page 139)
When you create a standard report, you may include functionality such as
level metrics, conditional metrics, and so forth that typically require the
MicroStrategy Engine to generate multiple passes of SQL to retrieve the
result set.
When you create a Freeform SQL report, you may also want to aggregate
metrics at different levels, apply conditions to selected data, or perform other
tasks that generally involve using multiple SQL passes. However, you cannot
simply type multiple passes of SQL separated by semicolons directly in the
Freeform SQL Editor. Databases expect multiple passes of SQL to be sent one
at a time for processing. However, at the ODBC level, all the SQL passes are
sent at once. Therefore, databases do not support processing multiple passes
of SQL separated by semicolons.
One method that you can use to simulate multiple passes of SQL is to embed
them in subqueries using derived and common table expressions. Before
using these expressions in Freeform SQL reports, you need to determine if
your database platform supports derived and common table expressions.
© 2014 MicroStrategy Inc. Using Derived and Common Table Expressions 129
4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
130 Using Derived and Common Table Expressions © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4
The databases you are using in this course are in SQL Server 2008 R2
Express, which supports both derived table expressions and common table
expressions. The example you will learn about in this course involves using
derived table expressions in a Freeform SQL report. However, you can use
the same steps to include a common table expression in a Freeform SQL
report. The only difference is in the syntax of the SQL statement that you pass
to the database, not the method.
Although this report contains only a couple of attributes and metrics, the
Percent Contribution to Region Overtime metric requires more complexity
than a single, simple pass of SQL.
© 2014 MicroStrategy Inc. Using Derived and Common Table Expressions 131
4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
To retrieve the result set for this report, you need to do the following:
• Aggregate the overtime hours for each employee (Overtime Hours metric)
• Aggregate the overtime hours for each employee region (necessary for
calculating the Percent Contribution to Region Overtime metric)
• Select the data for the final result set and calculate the Percent
Contribution to Region Overtime metric
The MicroStrategy Engine can easily retrieve this result in a standard report
by using multiple passes of SQL and creating temporary tables to store the
intermediate result sets. However, if you want to create this as a Freeform
SQL report, you cannot directly define the report SQL by using multiple SQL
statements separated by semicolons. One alternative for achieving this same
result in a Freeform SQL report is to use derived table expressions to create
subqueries. The subqueries perform the same functions as the individual
passes of Engine-generated SQL, but they eliminate the need to use multiple
passes of SQL.
If you create this report as a Freeform SQL report using derived table
expressions, the SQL looks like the following:
Derived Table Expression SQL
The syntax shown in the image above is for a SQL Server database.
Depending on your database platform, the exact syntax may vary.
Also, ensure that your database platform supports derived table
expressions.
132 Using Derived and Common Table Expressions © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4
In this statement, the first SELECT subquery in the outermost FROM clause
calculates the overtime hours for each employee region. Overtime hours data
is stored at the Employee level, so it has to be aggregated to the Employee
Region level.
The second SELECT subquery in the outermost FROM clause retrieves the
overtime hours for each employee. Because the overtime hours are stored at
the Employee level, there is no need to aggregate the data.
After defining the SQL statement for the Freeform SQL report using derived
table expressions, you need to map the columns in the outermost SELECT
clause: the Employee Region and Employee FFSQL attributes and the
Overtime Hours and Percent Contribution to Region Overtime metrics. The
Freeform SQL report definition looks like the following:
Freeform SQL Report Definition - Derived Table Expressions
© 2014 MicroStrategy Inc. Using Derived and Common Table Expressions 133
4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
If you save and execute this Freeform SQL report, you obtain the desired
result set:
Freeform SQL Report Result Set - Derived Table Expressions
display
In the image above, the Overtime Hours metric has been formatted to
as a fixed number using two decimal places, and the Percent
Contribution to Region Overtime metric has been formatted to display
as a percentage using two decimal places.
134 Using Derived and Common Table Expressions © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4
Alternatively, if a stored procedure does not exist for a query that you want to
execute, you can create a stored procedure in the database that includes the
SQL you want to use for a report. Then, you can define the SQL statement for
the Freeform SQL report by simply executing the stored procedure.
For example, to retrieve the data for the sample report, you could create a
stored procedure that looks like the following:
SQL for Creating Stored Procedure
The syntax shown in the image above is for a SQL Server database.
Depending on your database platform, the exact syntax may vary.
You execute this statement to create the stored procedure in your database. It
creates a stored procedure called spEMP_CONTR.
Within the stored procedure, the first statement retrieves the overtime hours
for each employee. Because the overtime hours are stored at the Employee
level, there is no need to aggregate the data. It also creates a temporary table
in which to store this intermediate result set.
The second statement calculates the overtime hours for each employee
region. Overtime hours data is stored at the Employee level, so it has to be
aggregated to the Employee Region level. It also creates a temporary table in
which to store this intermediate result set.
The last two statements simply remove the temporary tables that were
created from the database.
After you create the stored procedure, you can create a Freeform SQL report
that executes the stored procedure and displays the data from the final
SELECT statement as the report result set. You need to map the columns in
the final SELECT statement: the Employee Region and Employee FFSQL
attributes and the Overtime Hours and Percent Contribution to Region
Overtime metrics. The Freeform SQL report definition looks like the
following:
Freeform SQL Report Definition - Stored Procedure
The syntax shown in the image above is for a SQL Server database.
Depending on your database platform, the exact syntax for executing a
stored procedure may vary.
If you save and execute this Freeform SQL report, you obtain the desired
result set:
Freeform SQL Report Result Set - Stored Procedure
display
In the image above, the Overtime Hours metric has been formatted to
as a fixed number using two decimal places, and the Percent
Contribution to Region Overtime metric has been formatted to display
as a percentage using two decimal places.
So far in this course, you have learned about executing Freeform SQL reports
against databases. However, you can also use Freeform SQL reports to access
non-relational data sources such as a Microsoft Excel file or a text file. If you
have data that is stored in a Microsoft Excel file or text file, you can easily
analyze that data in Freeform SQL reports without having to import it into a
database.
4 Create a Freeform SQL report that executes against the Microsoft Excel
database instance.
The first step is to prepare the Microsoft Excel file by creating tables for the
data in the file. The instructions in this procedure are for Microsoft Excel
2010.
Ifforthequery
Microsoft Excel file you want to use has been created specifically
purposes, it may already contain tables for the data.
2 Ensure that all of the data columns have column headers that use the
appropriate syntax.
3 Ensure that you do not have missing data for any ID columns.
4 Select the rows and columns that you want to include in a table, including
the associated column headers.
While you should include the actual column header names for the
data, do not select the column headings at the top of the Microsoft
Excel spreadsheet (A, B, C, and so forth).
5 Right-click the selected rows and columns you want to include in the
table, point to Table, and select Convert to Range.
You will see the Table option only if you have formatted the data as
a table in the Excel spreadsheet. If you do not see the Table option,
go to step 7.
7 With the rows and columns still selected, right-click, and select Define
Name.
8 In the New Name window, in the Name box, type the table name you want
to use, and click OK.
9 Repeat steps 2 to 8 for any other data for which you want to create a table.
You can create as many tables as you want by selecting the desired
data and assigning a different table name.
11 On the File menu, point to Save As, and select Microsoft Excel 97-2003
Workbook. This ensures the workbook is saved as an .xls file.
When you save the file, ensure that it is not password protected.
The following image shows a Microsoft Excel file with multiple tables:
Microsoft Excel File with Multiple Tables
This Microsoft Excel file contains data that corresponds to several different
tables. The Table Name drop-down box, which is circled in the image above,
enables you to select a table. When you select a table, the corresponding data
is selected in the file.
In the image above, the data for the F_CUST_TXN_HIST table is selected.
This table contains data about individual transactions, including the
customer, products, date, revenue, cost, and number of items sold. To the
right of the selected table, you can also see the data for another table,
L_CUSTOMER, that contains customer IDs and names. Although you cannot
view them in the image, this file also contains data for product IDs and
descriptions and date IDs (L_PRODUCT and L_CAL_DATE, respectively).
Asalsoanreference
alternative to creating tables in a Microsoft Excel file, you can
data in a SQL query using the worksheet names in the
file. Worksheet names in a SQL query require specific syntax. For
example, if you want to retrieve customer IDs and names from a
worksheet named Customer Data, the SQL would look like the
following:
You always enclose worksheet names in brackets and end them with
“$”. You also need to enclose them in single quotes if the worksheet
names contain spaces. In the example above, the column names do not
contain spaces. However, if you do have column names that contain
spaces, you need to enclose them in brackets.
After you prepare the Microsoft Excel file, you are ready to create a DSN that
connects to the file. The steps for creating the DSN are similar to the steps
that you use for databases.
1 On the Start menu, select All Programs, select MicroStrategy Tools, and
select Connectivity Wizard.
4 Click Next.
6 Click Next.
7 In the ODBC Microsoft Excel Setup window, in the Data Source Name
box, type a name for the DSN.
10 Click OK.
The following image shows the ODBC Microsoft Excel Setup window with a
configured DSN:
ODBC Microsoft Excel Setup Window
The FFSQL_EXCEL DSN points to the Microsoft Excel file, which is named
Cust_Prod_Txn_Tables.xls.
After you set up the DSN, you are now ready to create a database instance in
MicroStrategy Developer that points to the DSN and configure it as a
Freeform SQL database instance. The steps for creating a database instance
for a Microsoft Excel file are similar to the steps that you use for databases,
with two slight differences.
1 For the database connection type, use the Generic DBMS connection type.
2 For the database login, select from any of the existing logins or create your
own database login.
The following image shows a database instance that points to the DSN for the
Microsoft Excel file:
Database Instance for Microsoft Excel File
The Excel Tables FFSQL database instance uses a database connection that
maps to the FFSQL_EXCEL DSN, which points to the
Cust_Prod_Txn_Tables.xls file. Notice that Microsoft Excel 2000/2003 is
selected as the database connection type.
After you create the database instance, you can configure it as a Freeform
SQL database instance using the Project Configuration window. The steps are
the same as for database instances that point to relational data sources.
The following image shows the Microsoft Excel database instance configured
as a Freeform SQL database instance:
Microsoft Excel Database Instance Configured for Freeform SQL
After creating and configuring the database instance, you are ready to create
a Freeform SQL report that executes against the Microsoft Excel file. For
example, the Cust_Prod_Txn_Tables.xls file contains customer transactional
data, so you could create a report that counts the number of transactions for
each customer. The definition for this Freeform SQL report would look like
the following:
Freeform SQL Report Definition - Microsoft Excel File
The SQL statement for this report selects the customer IDs and names and
counts the number of transactions for each customer. You map the columns
in the SELECT clause to the Customer FFSQL attribute and Count of
Transactions metric to display the appropriate information on the report.
The FROM clause in the SQL statement references the table names
you created in the Microsoft Excel file, not the name of the file itself.
The following image shows the first part of the result set for this report:
Freeform SQL Report Result Set - Microsoft Excel File
4 Create a Freeform SQL report that executes against the text database
instance.
You can query data from a single text file, or you can query and join
data from multiple text files. If you want to use multiple text files as
the data source for a Freeform SQL report, you need to store the files
in the same location.
The first step is to prepare the text file by verifying the following:
• Ensure that the text file has a ‘.txt’ or ‘.csv’ extension. You can use any
delimiter in the text file as long as it is supported by the ODBC driver that
you use to connect to the file.
• Ensure that the column names appear in the first row of the text file
Ittheisfirst
not an absolute requirement to include the column names in
row of the text file. However, if you include them in the
body of the text file, you avoid having to manually define the
columns of the text file when you create the DSN to connect to the
file.
The following image shows a sample text file that is comma delimited with
the column names in the first row of the text file:
Comma Delimited Text File
The first row in this text file lists the column names using the comma
delimiter. The remainder of the text file contains the actual data, which
consists of regions, states, account representatives, the number of accounts
each representative owns, and the combined revenue from all of the accounts
that each representative owns.
The most involved step in accessing a text file is creating the DSN that
connects to the file. Creating a DSN for a text driver consists of a few
additional steps that are necessary to define the format of the text file.
The MicroStrategy ODBC text driver installs with the software. This
embedded driver is the recommended one for accessing text files. If
you use any previous version of MicroStrategy, this driver is not
available as part of the software installation. The procedure for using
this driver is described in this lesson. You can also use the Microsoft
text driver, which is readily available within the ODBC Administrator.
If you use this driver, the procedure for creating the DSN is similar to
the one described in this lesson. However, some steps do vary because
of differences in the interfaces.
To create a DSN for a text file using the MicroStrategy ODBC text driver:
4 In the ODBC Data Source Administrator window, click the System DSN
tab.
7 Click Finish.
8 In the ODBC Text Driver Setup window, on the General tab, in the Data
Source Name box, type a name for the DSN.
9 In the Database Directory box, type the path for the text file.
12 In the Define File window, select the text file that you want to use as a
data source.
13 Click Open.
14 In the Define Table window, under Table Information, in the Table box,
type the table name that you want to use for the text file.
15 If the column names are in the first row of the text file, select the Column
Names in First Line check box.
Inserting the column names as the first row in the text file saves
you from having to manually define the column names. Instead,
the text driver can “guess” the column names and automatically
create the columns as part of the DSN definition.
16 In the Table Type drop-down box, select the delimiter that is used in the
text file.
Ifcharacter
you select Character as the delimiter, you need to type the
that is used as the text file delimiter in the Delimiter
Character box.
17 If the column names are in the first row of the text file, under Column
Information, click Guess.
Iffile,youyoudidmust
not include the column names as the first row of the text
manually define the columns.
18 If you “guess” the column names, verify the information for each of the
column names that are displayed.
The driver may not always correctly guess the data type for
columns. To modify the data type for a column, select the column.
In the Type drop-down box, select the correct data type. Click
Modify. In the Modify Column window, click OK.
19 Click OK.
Ifsteps
you are joining data from multiple text files, you need to repeat
12 to 19 to define the columns for each text file.
The following image shows the ODBC Text Driver Setup window when using
the MicroStrategy ODBC text driver:
ODBC Text Driver Setup Window
This window enables you to enter the DSN name and the directory in which
the text file is located.
The following image shows the Define Table window when using the
MicroStrategy ODBC text driver:
Define Table Window
This window enables you to select the specific text file, create a table name for
use in SQL statements, choose the delimiter, and define the columns for the
content of the text file. In this example, the FFSQL_TEXT DSN points to the
Account_Information.txt file, which is referenced by the table name
LU_ACCOUNT_INFO. Notice that the columns that display match the
column names contained in the first row of the text file.
After you set up the DSN, you are now ready to create a database instance in
MicroStrategy Developer that points to the DSN and configure it as a
Freeform SQL database instance. The steps for creating a database instance
for a text file are similar to the steps that you use for databases.
However, there are two slight variations. First, you should use the Generic
DBMS connection type since you are not connecting to a specific database
platform. Second, because you are not accessing a database that requires a
specific login, you can select from any of the existing logins or create your
own database login.
The following image shows a database instance that points to the DSN for the
text file:
Database Instance for Text File
The Text File FFSQL database instance uses a database connection that maps
to the FFSQL_TEXT DSN, which points to the Account_Information.txt file.
Notice that Generic DBMS is selected as the database connection type.
After you create the database instance, you can configure it as a Freeform
SQL database instance using the Project Configuration window. The steps are
the same as for database instances that point to relational data sources.
After creating and configuring the database instance, you are ready to create
a Freeform SQL report that executes against the text file. For example, the
Account_Information.txt file contains account revenue data, so you could
create a report that displays the number of accounts and amount of revenue
by region, state, and account representative for specific regions. The
definition for this Freeform SQL report would look like the following:
Freeform SQL Report Definition - Text File
The SQL statement for this report selects the region, state, and account
representative IDs and names and aggregates the number of accounts each
representative owns and the combined revenue of those accounts. It retrieves
only the data for the East and Pacific regions since those are the two regions
included in the WHERE clause. You map the columns in the SELECT clause
to the Region FFSQL, State, and Account Representative attributes and
Number of Accounts and Total Account Revenue metrics to display the
appropriate information on the report.
Inin the
this example, the FROM clause references the table name defined
DSN (LU_ACCOUNT_INFO) because the DSN uses the
MicroStrategy ODBC text driver. If you create a DSN using the
Microsoft text driver, you use the actual name of the text file in the
FROM clause (Account_Information.txt). The Microsoft text driver
does not enable you to define a table name for use in queries.
The following image shows the result set for this report:
Freeform SQL Report Result Set - Text File
Informatted
the image above, the Total Account Revenue metric has been
to display with no decimal places.
The report displays the number of accounts and total account revenue by
region, state, and account representative for the East and Pacific regions.
Lesson Summary
In this lesson, you learned:
• One method that you can use to simulate multiple passes of SQL is to
embed them in subqueries using derived and common table expressions.
• Another method that you can use to process multiple passes of SQL in
Freeform SQL report is to create stored procedures.
• You can use Freeform SQL reports to take advantage of the stored
procedures that exist in your database, rather than having to manually
enter your own custom SQL.
• You can use Freeform SQL reports to access non-relational data sources
such as a Microsoft Excel file or a text file.
Exercises
You should complete the following exercises using the MicroStrategy Tutorial
project, which is found in the MicroStrategy Analytics Modules project
source.
Overview
In this exercise, you will create a Freeform SQL report using derived table
expressions in the custom SQL statement to create conditional count metrics.
The purpose of this report is to analyze the number of customers in each city
who are in the 21 to 40 and 41 to 60 age ranges and then to determine what
percentage of customers in each city consists of customers in these two age
ranges.
You should create a report that displays the Customer City FFSQL attribute
as well as the following metrics:
You only need to display the attribute description form in the result
set, although you should include both the ID and description forms in
the report SQL.
You need to format the percent metrics to display as percentages with two
decimal places. Save the report in the Freeform SQL Exercises folder as
Targeted Customer Age Range Analysis.
Run the report. The result set should look like the following:
In creating this report, you will use tables from the FFSQL_CUST_WH
database. You can reference the physical schema for this warehouse in
Appendix A, Customer Analysis Schema.
Detailed Instructions
4 With the Create Freeform SQL report radio button selected, click OK.
7 In the Exercises SQL Microsoft Word document, copy the SQL labeled as
Targeted Customer Age Range Analysis and paste it into the SQL
Statement pane of the Freeform SQL Editor. The SQL looks like the
following:
8 Keep the Exercises SQL Microsoft Word document open as you will use it
later in the exercises.
10 In the Mapping pane, for Column 1, in the Object box, type Customer
City FFSQL as the attribute name. Leave the Form as ID.
12 In the Mapping pane, for Column 2, in the Object box, type Customer
City FFSQL as the attribute name.
15 In the Mapping pane, for Column 3, in the Object box, type Count of
Customers Age 21 to 40 as the metric name.
17 In the Mapping pane, for Column 4, in the Object box, type Percent of
Customers Age 21 to 40 as the metric name.
19 In the Mapping pane, for Column 5, in the Object box, type Count of
Customers Age 41 to 60 as the metric name.
21 In the Mapping pane, for Column 6, in the Object box, type Percent of
Customers Age 41 to 60 as the metric name.
22 Click OK.
24 In the Format Cells window, on the Number tab, under Category, select
Percent.
25 Click OK.
27 In the Format Cells window, on the Number tab, under Category, select
Percent.
28 Click OK.
31 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
Overview
In this exercise, using SQL Server Management Studio Express, you will
create a stored procedure in the FFSQL_CUST_WH database to aggregate
metrics at various levels and perform percent contribution calculations based
on those results. You should create this stored procedure using multiple
passes of SQL and temporary tables. The stored procedure should perform
the following actions:
After creating the stored procedure, create a Freeform SQL report that
executes the stored procedure. The purpose of this report is to analyze the
revenue for each product, the contribution of each individual product to the
revenue for its entire product group, and the contribution of each individual
product to the revenue across all products.
Create a report that displays the Product Group and Product attributes as
well as the following metrics:
• Product Revenue
You only need to display the attribute description forms in the result
set, although you should include both the ID and description forms in
the report SQL.
Format the revenue metric to display as currency with two decimal places.
Format the percent contribution to product group revenue metric to display
as a percentage with two decimal places. Format the percent contribution to
all revenue metric to display as a percentage with four decimal places. Save
the report in the Freeform SQL Exercises folder as Product Sales Analysis.
Run the report. The first part of the result set should look like the following:
In creating this report, you will use tables from the FFSQL_CUST_WH
database. You can reference the physical schema for this warehouse in
Appendix A, Customer Analysis Schema.
Detailed Instructions
1 On the Start menu, select All Programs, select Microsoft SQL Server
2008 R2, and select SQL Server Management Studio.
6 Click Connect.
7 If the Object Explorer is not displayed, on the View menu, select Object
Explorer.
10 In the Exercises SQL Microsoft Word document, copy the SQL labeled as
Product Sales Analysis (Stored Procedure Creation) and paste it into
the SQL pane of Microsoft SQL Server Management Studio Express. The
SQL looks like the following:
11 Keep the Exercises SQL Microsoft Word document open as you will use it
later in the exercises.
After you execute the query, you should see a message pane display
below the SQL pane that indicates that the command completed
successfully.
20 With the Create Freeform SQL report radio button selected, click OK.
23 In the Mapping pane, for Column 1, in the Object box, type Product
Group as the attribute name.
25 In the Mapping pane, for Column 2, in the Object box, type Product
Group as the attribute name.
32 In the Mapping pane, for Column 5, in the Object box, type Product
Revenue as the metric name.
34 In the Mapping pane, for Column 6, in the Object box, type Percent
Contribution of Product to Product Group Revenue as the metric
name.
36 In the Mapping pane, for Column 7, in the Object box, type Percent
Contribution of Product to All Revenue as the metric name.
37 Click OK.
39 In the Format Cells window, on the Number tab, under Category, select
Currency.
40 Click OK.
42 In the Format Cells window, on the Number tab, under Category, select
Percent.
43 Click OK.
45 In the Format Cells window, on the Number tab, under Category, select
Percent.
47 Click OK.
48 Save the report in the Freeform SQL Exercises folder as Product Sales
Analysis.
50 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
Overview
In this exercise, you will create a Microsoft Excel file that contains table data
from the FFSQL_EMP_WH database. You should import all of the data from
the F_SURVEY and L_EMP_DPTM tables and assign these same table
names to them in the Microsoft Excel file. Save the Microsoft Excel file as
Employee_Survey.xls in the C:\MSTR\FFSQL folder. Close the file.
After you have set up the appropriate connections, create a Freeform SQL
report that executes against the Employee_Survey.xls file. The purpose of
this report is to analyze the average satisfaction score by employee
department across all survey questions for 2011.
You should create a report that displays the Employee Department attribute
and an Average Satisfaction Score metric. You should filter the report to
include only 2011 data.
You need to format the metric to display as a fixed number with one decimal
place. Save the report in the Freeform SQL Exercises folder as 2011
Employee Survey Analysis.
Run the report. The result set should look like the following:
In creating this report, you will use tables from the FFSQL_EMP_WH
database. You can reference the physical schema for this warehouse in
Appendix B, Employee Analysis Schema.
Detailed Instructions
3 On the Data tab, click From Other Sources and select From SQL
Server.
4 In the Data Connection Wizard, in the Server name box, type your server
name.
IfSQLyouServer
are using a remote SQL Server machine rather than a local
on your own machine, you need to type the name of the
remote machine.
If\SQLEXPRESS
you are using Microsoft SQL Server Express, you will need to add
to your machine name.
5 Under Log on credentials, select the Use the following User Name and
Password option.
8 Click Next.
9 In the Select Database and Table window, in the drop-down box, select
the FFSQL_EMP_WH database.
12 Click Next.
13 Click Finish.
14 In the Import Data window, keep the default selections and click OK.
15 In the SQL Server Login window, in the Login ID box, type sa.
17 Click OK.
ItExcel.
may take a few seconds for the table data to display in Microsoft
18 In the Microsoft Excel worksheet, select the A1 cell and scroll down to the
bottom of the file.
22 With the data still selected, right-click, and select Define Name.
24 Click OK.
26 On the Data menu, click From Other Sources, and select From SQL
Server.
27 In the Data Connection Wizard window, in the Server name box, type
your server name.
28 Under Log on credentials, select the Use the following User Name and
Password option.
31 Click Next.
35 Click Next.
36 Click Finish.
37 In the Import Data window, keep the default selections and click OK.
38 In the SQL Server Login window, in the Login ID box, type sa.
40 Click OK.
ItExcel.
may take a few seconds for the table data to display in Microsoft
41 In the Microsoft Excel worksheet, select the H1 cell and scroll to the right.
This action selects all of the imported data for the second table.
43 Right-click the selected area, point to Table, and select Convert to
Range.
45 With the data still selected, right-click, and select Define Name.
47 Click OK.
1 On the Start menu, select All Programs, select MicroStrategy Tools, and
select Connectivity Wizard.
4 Click Next.
6 Click Next.
7 In the ODBC Microsoft Excel Setup window, in the Data Source Name
box, type EMP_SURVEY as the DSN name.
10 Click OK.
18 Click New.
You should have created this database login during the class
demonstrations. If you do not have this login, click New. In the
Database Logins window, in the Database login box, type Excel. In
the Login ID box, type Excel. Leave the Password box blank and
click OK.
22 Click OK.
24 Click OK.
33 With the Create Freeform SQL report radio button selected, click OK.
34 In the Exercises SQL Microsoft Word document, copy the SQL labeled as
2011 Employee Survey Analysis and paste it into the SQL Statement
pane of the Freeform SQL Editor. The SQL looks like the following:
36 In the Mapping pane, for Column 1, in the Object box, type Employee
Department as the attribute name.
38 In the Mapping pane, for Column 2, in the Object box, type Employee
Department as the attribute name.
41 In the Mapping pane, for Column 3, in the Object box, type Average
Satisfaction Score as the metric name.
42 Click OK.
44 In the Format Cells window, on the Number tab, under Category, select
Fixed.
46 Click OK.
47 Save the report in the Freeform SQL Exercises folder as 2011 Employee
Survey Analysis.
49 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
Overview
In this exercise, you will create a Freeform SQL report using three text files as
your data sources. You should use the Division.txt, Manager.txt, and
Employee.txt files in the C:\MSTR\FFSQL folder.
Create a DSN that connects to these three text files and name it
EMP_ORG_INFO. Create a database instance that points to this DSN and
name it Employee Organization Text Files. Configure this database
instance as a Freeform SQL database instance.
After you have set up the appropriate connections, create a Freeform SQL
report that executes against the Division.txt, Manager.txt, and Employee.txt
files. The purpose of this report is to analyze the number of employees that
report to each manager.
You should create a report that displays the Division and Manager FFSQL
attributes and a Number of Employees metric, which you can create by
counting the number of employees assigned to each manager. You need to
join information from all three files to obtain the correct result set.
You only need to display the attribute description forms in the result
set, although you should include both the ID and description forms in
the report SQL.
You should add subtotals to the report so that it displays the subtotal of
employees for each division and the grand total of employees across all
divisions. Save the report in the Freeform SQL Exercises folder as Employee
Organization Analysis.
Run the report. The result set should look like the following:
Detailed Instructions
1 On the Start menu, in the Search programs and files box, type
odbcad32.exe and press Enter.
3 In the ODBC Data Source Administrator window, on the System DSN tab,
click Add.
5 Click Finish.
6 In the ODBC Text Driver Setup window, on the General tab, in the Data
Source Name box, type EMP_ORG_INFO as the data source name.
7 In the Database Directory box, type C:\MSTR\FFSQL as the path for the
text files.
11 Click Open.
12 In the Define Table window, under Table Information, in the Table box,
type LU_DIVISION.
13 Ensure that the Column Names in First Line check box is selected.
14 In the Table Type drop-down box, ensure that Comma is selected as the
delimiter.
16 Verify that all the columns in the file are displayed and that the correct
data type is displayed for each column.
17 Click OK.
19 Click Open.
20 In the Define Table window, under Table Information, in the Table box,
type LU_MANAGER.
21 Select the Column Names in First Line check box if it is not already
selected.
22 In the Table Type drop-down box, ensure that Comma is selected as the
delimiter.
24 Verify that all the columns in the file are displayed and that the correct
data type is displayed for each column.
25 Click OK.
27 Click Open.
28 In the Define Table window, under Table Information, in the Table box,
type LU_EMPLOYEE.
30 In the Table Type drop-down box, ensure that Comma is selected as the
delimiter.
32 Verify that all the columns in the file are displayed and that the correct
data type is displayed for each column.
33 Click OK.
42 Click New.
You should have created this database login during the class
demonstrations. If you do not have this login, click New. In the
Database Logins window, in the Database login box, type Text. In
the Login ID box, type Text. Leave the Password box blank and
click OK.
46 Click OK.
48 Click OK.
57 With the Create Freeform SQL report radio button selected, click OK.
58 In the Exercises SQL Microsoft Word document, copy the SQL labeled as
Employee Organization Analysis and paste it into the SQL Statement
pane of the Freeform SQL Editor. The SQL looks like the following:
61 In the Mapping pane, for Column 1, in the Object box, type Division as
the attribute name.
63 In the Mapping pane, for Column 2, in the Object box, type Division as
the attribute name.
66 In the Mapping pane, for Column 3, in the Object box, type Manager
FFSQL as the attribute name.
68 In the Mapping pane, for Column 4, in the Object box, type Manager
FFSQL as the attribute name.
71 In the Mapping pane, for Column 5, in the Object box, type Number of
Employees as the metric name.
72 Click OK.
Add subtotals
73 In the Report Editor, in Design View, on the Data menu, select Subtotals.
75 Click OK.
78 Compare your results to the expected report in the Overview section at the
beginning of this exercise.
Lesson Description
This lesson describes how to configure the access control list for objects in
Freeform SQL reports and how to apply security filters to Freeform SQL
reports.
In this lesson, you will learn how permissions are applied in the access control
lists for existing project attributes and Freeform SQL objects in Freeform SQL
reports. You will also learn how to incorporate security filters in Freeform SQL
reports, including how to apply top and bottom range attributes.
Lesson Objectives
After completing the topics in this lesson, you will be able to:
• Explain how permissions are applied for existing project attributes and
Freeform SQL objects in Freeform SQL reports and configure the default
access control list settings for Freeform SQL objects. (Page 189)
Every object in a MicroStrategy project has an access control list (ACL) that
determines the permissions that different users or groups have for that
object. You can view the access control list for an object by viewing the
object’s properties.
The following image shows the access control list for a report:
Access Control List for a Report
For this report, the Administrator user and the Developers user group have
Full Control access. The Administrator user and users who belong to the
Developers user group can do anything with the report—view it, execute it,
modify it, delete it, and so forth. The Everyone and Public/Guest user groups
have only View access, which means users in these groups are more limited in
what they can do with this object. For example, they can view and execute the
report, but they do not have permissions to modify or delete it.
In the access control list of an object, you can assign the following levels of
access to users and groups:
• View—Enables the user or group to browse, read, use, and execute the
object
• Modify—Enables the user or group to browse, read, write, delete, use, and
execute the object
• Denied All—Prevents any level of access to the object for the user or
group (denies all permissions)
Toappropriate
modify the access control list of an object, you must have either
administrative privileges or Full Control access for the
object itself. For more information on access control lists and other
security settings, see the MicroStrategy Administration: Configuration
and Security course.
Everyone View
Public/Guest View
Whenever you create a new Freeform SQL object within a Freeform SQL
report, this default access control list is automatically applied to the object.
You can see this behavior by viewing the access control list of a Freeform SQL
object.
2 In the Report Editor, on the Data menu, select Freeform SQL Definition.
IfObjects
the Freeform SQL object is on the template or in the Report
window of the report, you can view the access control list
without opening the Freeform SQL Editor. On the template or in
the Report Objects window, right-click the object and select
Properties.
You can also view the access control list for a Freeform SQL object by
using the search function in MicroStrategy Developer to display the
object and then right-clicking the object and selecting Properties.
The following image shows the access control list for the Customer Education
attribute, which is a Freeform SQL object:
Access Control List for the Customer Education Attribute
Notice that the Customer Education attribute displays the object permissions
from the default access control list for Freeform SQL objects.
To modify the default access control list for new Freeform SQL objects:
3 Under Access control, besides Set Freeform SQL and MDX objects default
security, click Modify.
5 Click OK.
The following image shows the Project Configuration window with the access
control setting for Freeform SQL Objects highlighted:
Project Configuration Window - Access Control Setting for Freeform SQL
Objects
The following image shows the Properties window with the default settings
modified:
Properties Window - Modified Access Control List
In this example, the default access control list has been changed to include
Modify access for the Developers user group in addition to the default object
permissions.
After you change the default access control list for Freeform SQL objects, the
modified access control list applies to any new Freeform SQL objects that you
create. It does not affect any Freeform SQL objects that you created before
you changed the default access control list.
Ifobjects,
you need to modify the access control list for existing Freeform SQL
you can do so by accessing the Properties window for the
objects individually and then making the desired changes.
Notice that the access control list for the Employee Gender attribute includes
the Developers user group, granting them Modify access.
When a user executes a standard report, if that user, or a group to which the
user belongs to, has a security filter, it is included in the Engine-generated
SQL for the report. As a result, the query retrieves only data that meets the
conditions of the security filter as well as any filters on the report itself.
This report contains two filters in its definition—one to display data only for
specific regions (Northeast, Mid-Atlantic, and Southeast) and one to display
only Electronics data. However, this report displays all of the available
subcategories within the Electronics category.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 197
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
If a user with a security filter that only allows that user to view Computer
sales runs this same report, the result set looks like the following:
Report with Security Filter for Computers Subcategory
Now, the report displays data only for the Computers subcategory because
the user’s security filter is intersected with the original report filters.
• Filter Expression—The conditions that define the subset of data that the
security filter allows the user or group to view (for example, Region =
West)
• Top Range Attribute—The highest level of detail that the security filter
allows a user or group to view
All security filters contain a filter expression. They may or may not contain
top and bottom range attributes.
Tohavecreate and assign security filters to users and groups, you must
the appropriate administrative privileges. For more information
on security filters, see the MicroStrategy Administration:
Configuration and Security course.
198 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
Security filters are based on project attributes. You cannot create security
filters using Freeform SQL objects. Therefore, when you apply security filters
to a Freeform SQL report, they work as designed only if the report contains
corresponding project attributes.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 199
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
When you insert a security filter placeholder in a Freeform SQL report, you
use the Freeform SQL Security Filter Dialog window to define how you want
to apply security filters to the report. The following image shows the
Freeform SQL Security Filter Dialog window:
Freeform SQL Security Filter Dialog window
200 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
In the Freeform SQL Security Filter Dialog window, you need to configure the
following parameters:
• Select Level—Enables you to evaluate the report level against top and
bottom range attributes contained in the security filter. Select this option
only when you are sure that your query does not retrieve data outside the
restriction defined by the security filters.
You can insert a security filter placeholder into a Freeform SQL report using
the Insert Security Filter option. You can access this option on the Edit menu
in the Freeform SQL Editor, which is shown in the following image:
Edit Menu - Security Filter Option
You can also access this option onby right-clicking inside the SQL
Statement pane.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 201
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
1 In the Freeform SQL Editor, in the SQL Statement pane, place the cursor
at the point where you want to insert a security filter placeholder.
OR
You can add attributes to the security filter expression that are not
part of the SQL statement for the report. However, the report SQL
must include a table in the FROM clause that contains a column to
which you can map the string.
5 Select the attribute and click the upper > button to add it to the Attribute
Mapping pane.
6 In the Attribute Mapping pane, in the Form drop-down box, select the
form of the attribute.
You should select the form that security filters use to qualify on the
attribute.
202 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
7 In the String box, type the string that should replace the attribute form
when the security filter expression is generated for the report.
8 Repeat steps 4 to 7 for each attribute that you want to include in the
security filter expression for the report.
10 Select the attribute and click the lower > button to add it to the Ignored
Attributes pane.
11 Repeat steps 9 to 10 for each attribute that you want to ignore in the
security filter expression for the report.
12 If you want to evaluate the report level against top and bottom range
attributes, select the Allow security filters with Top and Bottom levels
to be evaluated based on the select level of this report check box.
13 Click OK.
When you finish defining the security filter placeholder, it is inserted into the
SQL statement at your cursor position. The placeholder displays in green,
underlined text.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 203
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
Security Filter
Freeform SQL Report Behavior
Configuration
If you have security filters that use top and bottom range attributes, these
settings also affect the behavior of Freeform SQL reports in addition to any
qualifications contained in the security filter. To enforce the appropriate
security, you can configure the security filter placeholder to evaluate the level
of the Freeform SQL report against the level allowed by a user’s security
filter. The following table describes the behavior of Freeform SQL reports
with regard to top and bottom range attributes in security filters:
204 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
Security Filter
Freeform SQL Report Behavior
Configuration
A security filter The report fails for users with security filters
placeholder exists and that have top and bottom range attributes.
the option to evaluate the
report level is not
configured
User A’s security filter contains conditions based on the Customer City and
Category attributes. User A is allowed to view data only for Pittsburgh for
Electronics.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 205
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
User B’s security filter contains conditions based on the Customer City and
Category attributes. User B is allowed to view data only for Seattle for Books.
User C’s security filter contains a condition based on the Customer City
attribute. It also includes the Customer attribute as the top range attribute.
User C is allowed to view data only for San Francisco at the Customer level or
below.
206 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
All three of these users need to execute the following Freeform SQL report:
Result Set - No Security Filter
Inas currency
the image above, the Revenue metric has been formatted to display
using two decimal places.
This report displays revenue by product and customer city. By default, users
who execute the report can view the entire result set. However, you want to
apply security filters to this report so that users can view data only for the
customer cities included in their respective security filters.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 207
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
To support security filters for this report, you need to insert a security filter
placeholder into the SQL statement for this report. The following image
shows the original Freeform SQL definition for the report:
Original Freeform SQL Definition
InnotthisFreeform
report, the Customer City attribute maps to project attribute,
SQL object.
Notice that the WHERE clause contains the table joins. You need to add the
security filter placeholder to the end of the WHERE clause.
208 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
You configure the security filter placeholder to look like the following:
Definition of Security Filter Placeholder
In this example, the security filters in use contain conditions for the
Customer City, and Category attributes. Because the report contains
Customer City data, you include this attribute when generating the security
filter expression for the report. The Customer City security filter conditions
are based on the description form. You map this attribute, select the
appropriate form, and provide the string that replaces it when the security
filter expression is generated. As a result, any security filter conditions based
on the Customer City description are applied when users execute this report.
The report does not contain any Category-specific data, so you can map
Category as an ignored attribute. As a result, any security filter conditions
based on the Category attribute are ignored when users execute this report.
Because User C has a security filter that contains a top range attribute, you
need to enable the option to evaluate the report level against top and bottom
range attributes.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 209
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
Finally, you are adding the security filter expression to the end of the
WHERE clause, so you need to type “and Security Filter” as the replacement
string.
After you insert this security filter placeholder, the definition of the Freeform
SQL report looks like the following:
Freeform SQL Definition with Security Filter Placeholder
Notice that the security filter placeholder displays in green, underlined text at
the end of the WHERE clause.
210 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
Now, if User A executes this report, the result set looks like the following:
Result Set - User A
The report returns data for all products but only for Pittsburgh because of
User A’s security filter. User A has no security filter for the Product attribute,
so all products are included in the result set. User’s A security filter for
Electronics is not applied since the Category attribute is ignored for this
report. The SQL for this report looks like the following:
Report SQL - User A
Notice that the end of the WHERE clause contains the filter condition for
Pittsburgh, which is intersected with the remainder of the WHERE clause.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 211
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
If User B executes this report, the result set looks like the following:
Result Set - User B
The report returns the data for all products but only for Seattle because of
User B’s security filter. User B has no security filter for the Product attribute,
so all products are included in the result set. User B’s security filter for Books
is not applied since the Category attribute is ignored for this report. The SQL
for this report looks like the following:
Report SQL - User B
Notice that the end of the WHERE clause contains the filter condition for
Seattle, which is intersected with the remainder of the WHERE clause.
212 Using Security Filters in Freeform SQL Reports © 2014 MicroStrategy Inc.
MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5
If User C executes this report, the report fails, and the following error occurs:
Report Error - User C
The report fails and returns an error because User C’s security filter has
Customer as a top range attribute. As a result, User C is not allowed to see
data at a level higher than Customer. The level of the report is Customer City,
which is a higher-level attribute than Customer. Therefore the report fails.
As you can see, each user receives very different result sets, because each
result set is based on the security filter of the user who executed the report.
Security filter conditions are included or ignored, depending on how you
configure the security filter placeholder.
© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 213
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials
Lesson Summary
In this lesson, you learned:
• Freeform SQL objects inherit the default access control list defined at the
project level.
Appendix Description
Customer Schema
Product Schema
Time Schema
Transaction Schema
Appendix Description
Benefits Schema
Compensation Schema
Contractor Schema
Employee Schema
Jobs Schema
Qualification Schema
Survey Schema
Time Schema
A comparison
Freeform SQL and standard reports 24
access control list
configuring Freeform SQL database
Freeform SQL objects 189 instances 36
access control list, levels of access 190 course overview 30
accessing non-relational data sources creating Freeform SQL reports 43
overview 139 creating tables
accessing the Freeform SQL Editor 39 Microsoft Excel files 140
accessing the Freeform SQL Editor for ex-
isting Freeform SQL reports 41
adding new prompts D
Freeform SQL reports 101 data manipulations
administrative functions Freeform SQL reports 25
Freeform SQL reports 29 database instance
Freeform SQL report creation 43
B database instance configuration
Freeform SQL reports 36
benefits
database instances
Freeform SQL 23
Microsoft Excel files 143
text files 152
C default access control list
column mapping Freeform SQL objects 191
Freeform SQL report creation 46 defining the SQL statement
common table expressions Freeform SQL report creation 44
overview 129 deleting managed objects 63
support 130 derived table expressions
S T
saving Freeform SQL reports 51 text files
search options configuring database instances 152
managed objects 59 Freeform SQL report creation 147
security filter interaction preparing 148
Freeform SQL reports 204 text files, creating DSNs 149
security filter parameters text files, Freeform SQL report
creation 155
Freeform SQL reports 200
security filter placeholders
Freeform SQL reports 201 V
security filters value prompts 99
Freeform SQL reports 197 Freeform SQL reports 107
security filters and Freeform SQL viewing managed objects 57
example 205 VLDB properties
selecting the database instance Freeform SQL reports 28
Freeform SQL report creation 43
shortcut metrics
Freeform SQL reports 27
SQL guidelines
Freeform SQL reports 45
SQL statement
Freeform SQL report creation 44
standard and Freeform SQL reports
comparison 24
stored procedures
Freeform SQL report creation 136
stored procedures, overview 135
structure
Freeform SQL reports 21