Sei sulla pagina 1di 228

MICROSTRATEGY FREEFORM SQL ESSENTIALS

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

All Contents Copyright © 2014 MicroStrategy Incorporated. All Rights Reserved.

Trademark Information

MicroStrategy, MicroStrategy 6, MicroStrategy 7, MicroStrategy 7i, MicroStrategy 7i Evaluation Edition,


MicroStrategy 7i Olap Services, MicroStrategy 8, MicroStrategy 9, MicroStrategy Distribution Services, MicroStrategy
MultiSource Option, MicroStrategy Command Manager, MicroStrategy Enterprise Manager, MicroStrategy Object
Manager, MicroStrategy Reporting Suite, MicroStrategy Power User, MicroStrategy Analyst, MicroStrategy Consumer,
MicroStrategy Email Delivery, MicroStrategy BI Author, MicroStrategy BI Modeler, MicroStrategy Evaluation Edition,
MicroStrategy Administrator, MicroStrategy Agent, MicroStrategy Architect, MicroStrategy BI Developer Kit,
MicroStrategy Broadcast Server, MicroStrategy Broadcaster, MicroStrategy Broadcaster Server, MicroStrategy
Business Intelligence Platform, MicroStrategy Consulting, MicroStrategy CRM Applications, MicroStrategy Customer
Analyzer, MicroStrategy Desktop, MicroStrategy Desktop Analyst, MicroStrategy Desktop Designer, MicroStrategy
eCRM 7, MicroStrategy Education, MicroStrategy eTrainer, MicroStrategy Executive, MicroStrategy Infocenter,
MicroStrategy Intelligence Server, MicroStrategy Intelligence Server Universal Edition, MicroStrategy MDX Adapter,
MicroStrategy Narrowcast Server, MicroStrategy Objects, MicroStrategy OLAP Provider, MicroStrategy SDK,
MicroStrategy Support, MicroStrategy Telecaster, MicroStrategy Transactor, MicroStrategy Web, MicroStrategy Web
Business Analyzer, MicroStrategy World, Application Development and Sophisticated Analysis, Best In Business
Intelligence, Centralized Application Management, Information Like Water, Intelligence Through Every Phone,
Intelligence To Every Decision Maker, Intelligent E-Business, Personalized Intelligence Portal, Query Tone, Rapid
Application Development, MicroStrategy Intelligent Cubes, The Foundation For Intelligent E-Business, The Integrated
Business Intelligence Platform Built For The Enterprise, The Platform For Intelligent E-Business, The Scalable
Business Intelligence Platform Built For The Internet, Office Intelligence, MicroStrategy Office, MicroStrategy Report
Services, MicroStrategy Web MMT, MicroStrategy Web Services, Pixel Perfect, Pixel-Perfect, MicroStrategy Mobile,
MicroStrategy Integrity Manager and MicroStrategy Data Mining Services are all registered trademarks or trademarks
of MicroStrategy Incorporated.

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

MicroStrategy Education Services MicroStrategy Incorporated


1850 Towers Crescent Plaza 1850 Towers Crescent Plaza
Tysons Corner, VA 22182 Tysons Corner, VA 22182
Phone: 877.232.7168 Phone: 703.848.8600
Fax: 703.848.8602 Fax: 703.848.8610
E-mail: education@microstrategy.com E-mail: info@microstrategy.com
http://www.microstrategy.com/education http://www.microstrategy.com
TABLE OF CONTENTS

Preface Course Description...................................................................... 9


Who Should Take This Course .............................................. 10
Course Prerequisites ............................................................. 10
Follow-Up Courses ................................................................ 10
Course Objectives ................................................................. 11
About the Course Materials ......................................................... 12
Content Descriptions ............................................................. 12
Learning Objectives ............................................................... 12
Lessons ................................................................................. 12
Opportunities for Practice ...................................................... 13
Typographical Standards ....................................................... 13
MicroStrategy Courses ................................................................ 16
Core Courses......................................................................... 16
Advanced Courses ................................................................ 17

1. Introduction to Lesson Description ................................................................... 19


Freeform SQL Lesson Objectives ................................................................. 20
Reporting
What is Freeform SQL? ............................................................... 21
What Are the Benefits of Using Freeform SQL?.......................... 23
Comparison of Freeform SQL and Standard Reports ................. 24
Report Formatting and Data Manipulations ........................... 25
Administrative Functions........................................................ 29
Overview of Freeform SQL Reporting ......................................... 30
Lesson Summary......................................................................... 31

© 2014 MicroStrategy Inc. 5


Table of Contents MicroStrategy Freeform SQL Essentials

2. Creating Freeform Lesson Description ................................................................... 33


SQL Reports Lesson Objectives ................................................................. 34
Overview of Freeform SQL Report Creation................................ 35
Configuring a Freeform SQL Database Instance......................... 36
Review of Database Instances .............................................. 36
Configuring a Database Instance for Freeform SQL.............. 37
The Freeform SQL Editor ............................................................ 39
Accessing the Freeform SQL Editor ...................................... 39
Creating a Freeform SQL Report................................................. 43
Selecting the Database Instance ........................................... 43
Defining the SQL Statement .................................................. 44
Mapping the Columns ............................................................ 46
Saving the Freeform SQL Report .......................................... 51
Managed Objects......................................................................... 55
What Is A Managed Object? .................................................. 55
Viewing Managed Objects ..................................................... 57
Editing Managed Objects....................................................... 60
Deleting Managed Objects .................................................... 63
Filters and Freeform SQL Reports............................................... 65
Drilling on Freeform SQL Reports ............................................... 68
Using Freeform SQL Reports in Documents ............................... 74
Lesson Summary......................................................................... 76
Exercises ..................................................................................... 77
Exercise 2.1: Creating a New Folder ..................................... 77
Exercise 2.2: Configuring a New Freeform SQL Database
Instance ................................................................................. 78
Exercise 2.3: Creating a Basic Freeform SQL Report ........... 79
Exercise 2.4: Manipulating a Basic Freeform SQL Report .... 83
Exercise 2.5: Configuring a Second Freeform SQL Database
Instance ................................................................................. 86
Exercise 2.6: Creating a Freeform SQL Report Using the
Second Database Instance.................................................... 88
Exercise 2.7: Modifying the Filter Conditions of a Freeform SQL
Report .................................................................................... 92

3. Prompts in Freeform Lesson Description ................................................................... 97


SQL Reports Lesson Objectives ................................................................. 98
Using Prompts in Freeform SQL Reports .................................... 99
Creating a Freeform SQL Report with Prompts......................... 100
Adding a New Prompt to a Freeform SQL Report ............... 101

6 © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Table of Contents

Inserting an Existing Prompt in a Freeform SQL Report...... 102


Using Element List Prompts in a Freeform SQL Report ...... 103
Using Value Prompts in a Freeform SQL Report................. 107
Using Optional Prompts in a Freeform SQL Report............. 111
Lesson Summary....................................................................... 116
Exercises ................................................................................... 117
Exercise 3.1: Using an Element List Prompt in a Freeform SQL
Report .................................................................................. 117
Exercise 3.2: Using a Value Prompt in a Freeform SQL Report
122

4. Advanced Topics for Lesson Description ................................................................. 127


Freeform SQL Reports Lesson Objectives ............................................................... 128
Using Derived and Common Table Expressions ....................... 129
Derived Table Expressions .................................................. 130
Common Table Expressions................................................ 130
Derived Versus Common Table Expressions ...................... 130
Creating a Freeform SQL Report Using Derived Table
Expressions ......................................................................... 131
Using Stored Procedures........................................................... 135
Creating a Freeform SQL Report Using Stored Procedures 136
Accessing Non-relational Data Sources .................................... 139
Using Microsoft Excel Files for Freeform SQL Reports ....... 139
Using Text Files for Freeform SQL Reports......................... 147
Lesson Summary....................................................................... 157
Exercises ................................................................................... 159
Exercise 4.1: Creating a Freeform SQL Report with Derived
Table Expressions ............................................................... 159
Exercise 4.2: Creating a Freeform SQL Report with a Stored
Procedure ............................................................................ 163
Exercise 4.3: Using a Microsoft Excel File for a Freeform SQL
Report .................................................................................. 170
Exercise 4.4: Using Text Files for a Freeform SQL Report.. 178

5. Security for Freeform Lesson Description ................................................................. 187


SQL Reports Lesson Objectives ............................................................... 188
Configuring Access to Freeform SQL Objects........................... 189
Access Control List for Objects in Freeform SQL Reports... 191
Modifying the Default Access Control List for Freeform SQL
Objects................................................................................. 193
Using Security Filters in Freeform SQL Reports........................ 197

© 2014 MicroStrategy Inc. 7


Table of Contents MicroStrategy Freeform SQL Essentials

Applying Security Filters to Freeform SQL Reports ............. 199


Lesson Summary....................................................................... 214

A. Customer Analysis Appendix Description.............................................................. 215


Schema
Customer Analysis Schema....................................................... 216
Customer Schema ............................................................... 216
Product Schema .................................................................. 217
Time Schema....................................................................... 217
Transaction Schema ............................................................ 218
Fact Tables Schema ............................................................ 218

B. Employee Analysis Appendix Description.............................................................. 219


Schema
Employee Analysis Schema ...................................................... 220
Benefits Schema.................................................................. 220
Compensation Schema ....................................................... 220
Contractor Schema .............................................................. 221
Employee Schema............................................................... 221
Employee Status Schema ................................................... 222
Jobs Schema ....................................................................... 222
Qualification Schema ........................................................... 222
Survey Schema ................................................................... 223
Time Schema....................................................................... 223
Time Off Schema ................................................................. 224
Fact Tables Schema ............................................................ 224

Index ......................................................................................... 225

8 © 2014 MicroStrategy Inc.


PREFACE

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.

This course introduces students to the concept of Freeform SQL reports, a


feature in MicroStrategy Developer that enables users to write custom SQL
that executes against a data source to generate a report. Students will learn
about the benefits of using Freeform SQL reports and the differences between
Freeform SQL and standard MicroStrategy reports. After this overview of
Freeform SQL reporting, students will learn how to create and use Freeform
SQL reports, including working with managed objects, incorporating prompts,
using derived and common table expressions and stored procedures, accessing
non-relational data sources, and configuring security.

After taking this course, students will understand how to implement Freeform
SQL reporting as part of a MicroStrategy project.

© 2014 MicroStrategy Inc. 9


Preface MicroStrategy Freeform SQL Essentials

Who Should Take This Course


This course is designed for:

• Report developers

• Advanced business analysts

• Anyone who has an interest in learning how to create reports with


user-defined SQL queries

Course Prerequisites
Before starting this course, you should be familiar with:

• MicroStrategy Developer: Reporting Essentials

• MicroStrategy Architect: Project Design Essentials

• SQL

Follow-Up Courses
• This course does not have any recommended follow-up courses.

10 Who Should Take This Course © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Preface

Course Objectives
After completing this course, you will be able to:

• Explain the purpose of Freeform SQL reports, describe the benefits of


using Freeform SQL reports, identify the differences in functionality
between Freeform SQL reports and standard MicroStrategy reports, and
describe the topics that are covered in this course. (Page 20)

• Describe the process of creating a Freeform SQL report, configure


Freeform SQL database instances, use the Freeform SQL Editor to create
Freeform SQL reports, work with managed objects, add filter conditions to
Freeform SQL reports, explain the drilling behavior for Freeform SQL
reports, and describe how you can use Freeform SQL reports in Report
Services documents. (Page 34)

• 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)

© 2014 MicroStrategy Inc. Course Objectives 11


Preface MicroStrategy Freeform SQL Essentials

About the Course Materials


This course is organized into lessons and reference appendices. Each lesson
focuses on major concepts and skills that help you to better understand
MicroStrategy products and use them to implement MicroStrategy projects.
The appendices provide you with supplemental information to enhance your
knowledge of MicroStrategy products.

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:

• Course—You will achieve these overall objectives by successfully


completing all the lessons in this course. The Course Objectives heading
in this Preface contains the list of course objectives.
• Lesson—You will achieve these main objectives by successfully
completing all the topics in the lesson. You can find the primary lesson
objectives directly under the Lesson Objectives heading at the beginning
of each lesson.

• Main Topic—You will achieve this secondary objective by successfully


completing the main topic. The topic objective is stated at the beginning
of the topic text. You can find a list of all the topic objectives in each lesson
under the Lesson Objectives heading at the beginning of each lesson.

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.

12 About the Course Materials © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Preface

Opportunities for Practice


A Workshop is a reinforcement and assessment activity that follows two or
more lessons. Because a Workshop covers content and applied skills
presented in several lessons, it is a separate section on the level of a lesson.

The following sections within lessons provide you with opportunities to


reinforce important concepts, practice new product and project skills, and
monitor your own progress in achieving the lesson and course 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:

Click Select Warehouse.

Code

References to code, formulas, or calculations within paragraphs are


formatted in regular Courier.New font style. The following example shows
this style:

Sum(sales)/number of months

© 2014 MicroStrategy Inc. About the Course Materials 13


Preface MicroStrategy Freeform SQL Essentials

Data Entry

References to literal data you must type in an exercise or procedure are in


bold Arial typeface. References to data you type in that could vary from user
to user or system to system is in bold italic Arial font style. The following
example shows this style:

Type copy c:\filename d:\foldername\filename.

Keyboard Keys

References to a keyboard key or shortcut keys are in uppercase letters in bold


Arial font style. The following example shows this style:

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:

The aggregation level is the level of calculation for the metric.

Notes and Warnings

 A note icon indicates helpful information.


 Ayouwarning icon calls your attention to very important information that
should read before continuing the course.

Heading Icons

The following heading icons are used to indicate specific practice and review
sections:

 — Precedes a Review section

14 About the Course Materials © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Preface

 — Precedes a Case Study

 — Precedes a Business Scenario

 — Precedes Exercises

© 2014 MicroStrategy Inc. About the Course Materials 15


Preface MicroStrategy Freeform SQL Essentials

MicroStrategy Courses

Core Courses
• Implementing MicroStrategy: Development and Deployment

• MicroStrategy Web Essentials

• MicroStrategy Web for Reporters and Analysts

• MicroStrategy Web for Professionals

• MicroStrategy Visual Insight Essentials

• MicroStrategy Report Services: Documents and Dashboards

• MicroStrategy Mobile for App Developers

• MicroStrategy Architect: Project Design Essentials

• MicroStrategy Developer: Reporting Essentials

• MicroStrategy Developer: Advanced Reporting

• MicroStrategy Office Essentials

16 MicroStrategy Courses © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Preface

Advanced Courses
• MicroStrategy Administration: Configuration and Security

• MicroStrategy Administration: Application Management

• MicroStrategy Engine Essentials

• MicroStrategy Architect: Advanced Project Design

• MicroStrategy Advanced Data Warehousing

• MicroStrategy Data Mining and Advanced Analytics

• MicroStrategy Developer: Advanced Reporting Case Studies

• MicroStrategy Freeform SQL Essentials

• MicroStrategy Transaction Services for Mobile App and Dashboard


Developers

• MicroStrategy Web SDK: Customization Essentials

• MicroStrategy Web SDK: Customizing Security

• MicroStrategy Web SDK: Portal Integration

All courses are subject to change. Please visit the MicroStrategy website for the latest
education offerings.

© 2014 MicroStrategy Inc. MicroStrategy Courses 17


Preface MicroStrategy Freeform SQL Essentials

18 MicroStrategy Courses © 2014 MicroStrategy Inc.


1
INTRODUCTION TO FREEFORM
SQL REPORTING

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.

© 2014 MicroStrategy Inc. 19


1 Introduction to Freeform SQL Reporting MicroStrategy Freeform SQL Essentials

Lesson Objectives

After completing this lesson, you will be able to:


Explain the purpose of Freeform SQL reports, describe the benefits of using
Freeform SQL reports, identify the differences in functionality between
Freeform SQL reports and standard MicroStrategy reports, and describe the
topics that are covered in this course.

After completing the topics in this lesson, you will be able to:

• Explain the purpose of MicroStrategy Freeform SQL reports. (Page 21)

• Describe the benefits of using Freeform SQL reports in a MicroStrategy


project. (Page 23)

• Identify the differences in functionality between Freeform SQL reports


and standard MicroStrategy reports. (Page 24)

• Describe the topics that are covered in this course. (Page 30)

20 Lesson Objectives © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Introduction to Freeform SQL Reporting 1

What is Freeform SQL?

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.

However, you can also develop reports in MicroStrategy Developer using


another method. You can create Freeform SQL reports, which enable you to
enter your own custom SQL and then use that SQL to retrieve data from a
variety of data sources, including other relational databases, operational
databases, Microsoft Excel spreadsheets, and text files.

The following image shows the difference in structure of standard


MicroStrategy reports and Freeform SQL reports:
Standard and Freeform SQL 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.

© 2014 MicroStrategy Inc. What is Freeform SQL? 21


1 Introduction to Freeform SQL Reporting MicroStrategy Freeform SQL Essentials

Although you can create Freeform SQL reports only in MicroStrategy


Developer, you can import data using a freeform script in MicroStrategy
Web. After importing data using a freeform script and publishing an
Intelligent Cube, you can create a report, document, or Visual Insight
dashboard. For more information regarding importing data using a freeform
script, refer to the MicroStrategy Web Help.

Additionally, you can access Freeform SQL reports using various


MicroStrategy interfaces after you have created them. You can run Freeform
SQL reports from MicroStrategy Developer, MicroStrategy Web and
MicroStrategy Office. You can incorporate them as Freeform SQL reports in a
MicroStrategy Report Services document.

22 What is Freeform SQL? © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Introduction to Freeform SQL Reporting 1

What Are the Benefits of Using Freeform SQL?

After completing this topic, you will be able to:


Describe the benefits of using Freeform SQL reports in a MicroStrategy
project.

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

• Tune MicroStrategy SQL Engine-generated SQL to suit specific reporting


needs

 You cannot tune MicroStrategy Analytical Engine SQL.


• Rapidly prototype reports against new data that has not yet been included
in your data warehouse

• Retrieve data from multiple data sources and merge it into a single report
container

 You can achieve this requirement by using Freeform SQL reports


in conjunction with Report Services documents.

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

Comparison of Freeform SQL and Standard


Reports

After completing this topic, you will be able to:


Identify the differences in functionality between Freeform SQL reports and
standard MicroStrategy reports.

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.

24 Comparison of Freeform SQL and Standard Reports © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Introduction to Freeform SQL Reporting 1

Report Formatting and Data Manipulations


You can perform most standard formatting and data manipulations on
Freeform SQL reports. However, they do not support some functions and
only partially support others. The following table lists commonly-used
reporting functions and identifies the level of support that Freeform SQL
reports provide:
Freeform SQL Support for Reporting Functions

Partially Not
Function Supported
Supported Supported

Printing X

Sending the report to history X

Custom grid formatting X

Custom graph formatting X

Using all report views (Design, X


Grid, Graph, Grid and Graph,
and SQL)

Using the Report Objects X


window (MicroStrategy OLAP
Services)

View filters (MicroStrategy X


OLAP Services)

Page-by X

Derived metrics X
(MicroStrategy OLAP
Services)

Shortcut metrics X

Sorting X

Subtotals X

Thresholds X

Drilling X

Modifying the attribute form X


display

Using Report Data Options X


features

VLDB properties X

Data marting X

© 2014 MicroStrategy Inc. Comparison of Freeform SQL and Standard Reports 25


1 Introduction to Freeform SQL Reporting MicroStrategy Freeform SQL Essentials

Freeform SQL Support for Reporting Functions

Partially Not
Function Supported
Supported Supported

Exporting X

Re-executing the report X

Reprompting the report (if it X


contains prompts)

Changing the report autostyle X

Creating custom autostyles X

Outline mode X

Merging/locking row and X


column headers

Changing report column X


widths

Custom banding X

Data pivoting X

Swapping rows and columns X


of the report

Save as report template or X


filter

Custom groups X

Consolidations X

Transformations X

Filters (using filter objects that X


are defined in MicroStrategy
Developer)

Using the report as a filter on X


another report

Using the report as a dataset X


in a MicroStrategy Report
Services document

Executing the report in X


MicroStrategy Web

26 Comparison of Freeform SQL and Standard Reports © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Introduction to Freeform SQL Reporting 1

 You cannot use custom groups, consolidations, transformations, and


report filters in Freeform SQL reports as all of these objects require
the MicroStrategy Engine to generate additional SQL. You can define
filter conditions directly in the WHERE clause of the custom SQL for a
Freeform SQL report. For more information about adding filter
conditions to Freeform SQL reports, see the “Creating Freeform SQL
Reports” lesson starting on page 33.

If a reporting function is available in both MicroStrategy Developer and


MicroStrategy Web, you can use it in conjunction with Freeform SQL reports
in either interface.

Although MicroStrategy fully supports most reporting functionality for


Freeform SQL reports, it is helpful to understand the specific limitations that
do exist. The following sections provide more detail on functions that are
only partially supported.

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

In a standard report, you can create three types of shortcut metrics:

• 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.

© 2014 MicroStrategy Inc. Comparison of Freeform SQL and Standard Reports 27


1 Introduction to Freeform SQL Reporting MicroStrategy Freeform SQL Essentials

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.

Report Data Options Features

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.

Report-level VLDB Properties

Report-level VLDB properties enable you to change how the MicroStrategy


Engine generates SQL. By definition, Freeform SQL reports involve using
your own custom SQL instead of Engine-generated SQL. As such, many of
these VLDB properties do not apply and therefore, are not available for
Freeform SQL reports. You do have access to Analytical Engine properties as
well as select Governing and Pre/Post Statements properties.

28 Comparison of Freeform SQL and Standard Reports © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Introduction to Freeform SQL Reporting 1

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.

 For more information about using security features in conjunction


with Freeform SQL reports, see the “Security for Freeform SQL
Reports” lesson starting on page 187.

© 2014 MicroStrategy Inc. Comparison of Freeform SQL and Standard Reports 29


1 Introduction to Freeform SQL Reporting MicroStrategy Freeform SQL Essentials

Overview of Freeform SQL Reporting

After completing this topic, you will be able to:


Describe the topics that are covered in this course.

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.

The remainder of this course explains how to implement Freeform SQL


reports in a MicroStrategy project. This course is divided into the following
four lessons:

• Creating Freeform SQL Reports—Describes the process of Freeform SQL


report creation, including configuring Freeform SQL database instances,
using the Freeform SQL Editor, working with managed objects, adding
filter conditions to Freeform SQL reports, drilling on Freeform SQL
reports, and using Freeform SQL reports in Report Services documents

• Prompts in Freeform SQL Reports—Describes how to use element list


and value prompts in Freeform SQL reports

• Advanced Topics for Freeform SQL Reports—Describes how to create


Freeform SQL reports using derived expressions, common table
expressions, and stored procedures

• Security for Freeform SQL Reports—Describes how to configure object


security for Freeform SQL objects and use security filters in Freeform
SQL reports

30 Overview of Freeform SQL Reporting © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Introduction to Freeform SQL Reporting 1


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.

• For a Freeform SQL report, drilling is limited to attributes within the


personal Intelligent Cube.

• 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.

• Report caching, scheduling or subscribing to reports, job prioritization,


object-level security, security filters and governing are available for
Freeform SQL reports.

© 2014 MicroStrategy Inc. Lesson Summary 31


1 Introduction to Freeform SQL Reporting MicroStrategy Freeform SQL Essentials

32 Lesson Summary © 2014 MicroStrategy Inc.


2
CREATING 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.

© 2014 MicroStrategy Inc. 33


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Lesson Objectives

After completing this lesson, you will be able to:


Describe the process of creating a Freeform SQL report, configure Freeform
SQL database instances, use the Freeform SQL Editor to create Freeform
SQL reports, work with managed objects, add filter conditions to Freeform
SQL reports, explain the drilling behavior for Freeform SQL reports, and
describe how you can use Freeform SQL reports in Report Services
documents.

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)

• Access the Freeform SQL Editor in MicroStrategy Developer and describe


its components. (Page 39)

• 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 filter conditions are included in Freeform SQL reports.


(Page 65)

• Describe the drilling behavior of Freeform SQL reports. (Page 68)

• Describe how you can use Freeform SQL reports in Report Services
documents. (Page 74)

34 Lesson Objectives © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

Overview of Freeform SQL Report Creation

After completing this topic, you will be able to:


Describe the steps involved in creating Freeform SQL reports.

Now that you understand the basic premise of using Freeform SQL reports,
you are ready to learn how to create them in MicroStrategy Developer.

To create a Freeform SQL report, you perform the following steps:

1 Configure a Freeform SQL database instance that points to the data


source that you want to use.

2 Create a report using the Freeform SQL Editor.

3 Select the database instance that you want to use as a data source.

4 Define the SQL statement for the report.

5 Map all of the columns in the SELECT clause of the SQL statement.

6 Save the report with the Freeform SQL definition.

You will learn in detail about performing each of these steps throughout this
lesson.

© 2014 MicroStrategy Inc. Overview of Freeform SQL Report Creation 35


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Configuring a Freeform SQL Database Instance

After completing this topic, you will be able to:


Configure a Freeform SQL database instance that you can use for Freeform
SQL reports.

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.

Review of Database Instances


A database instance is the logical object in MicroStrategy Developer that
typically represents a connection to a data warehouse. Whenever you run a
report, you connect to the data warehouse using the DSN, login, and
password stored as part of the database instance definition.

 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.

36 Configuring a Freeform SQL Database Instance © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

Configuring a Database Instance for Freeform SQL


Whether you want to access an operational database, another relational
database other than the project data warehouse, or a non-relational data
source like a Microsoft Excel spreadsheet, you need to configure a database
instance that enables MicroStrategy Intelligence Server (or MicroStrategy
Developer, if you are working in 2-tier) to connect to it and retrieve the
requested data.

 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.

To configure a database instance for Freeform SQL reporting:

1 In MicroStrategy Developer, in the appropriate project source, create a


database instance to connect to the desired data source.

 You may also need to create a new database connection and


database login as part of this step.

2 Under the project source, right-click the project in which you want to
create Freeform SQL reports and select Project Configuration.

3 In the Project Configuration window, in the Categories list, expand the


Database instances category.

4 In the SQL Data warehouses subcategory, under Available Data Mart,


Query Builder, Freeform and non-primary warehouse database instances,
select the database instance that you created.

5 In the message window, click No.

 Optimization applies only if you are configuring a database


instance for use with data marts.

6 In the Project Configuration window, click OK.

© 2014 MicroStrategy Inc. Configuring a Freeform SQL Database Instance 37


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

The following image shows the available database instances in the Project
Configuration window:
Available Database Instances in Project Configuration Window

 Configured database instances listed in bold text have at least one


object in the project that depends on that database instance, such as a
logical table, Freeform SQL report, or Query Builder report.

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.

38 Configuring a Freeform SQL Database Instance © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

The Freeform SQL Editor

After completing this topic, you will be able to:


Access the Freeform SQL Editor in MicroStrategy Developer and describe its
components.

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.

Accessing the Freeform SQL Editor


You can easily access the Freeform SQL Editor from any project in
MicroStrategy Developer.

To access the Freeform SQL Editor:

1 Open the Report Editor just as you would for creating a standard report.

2 In the New Grid window, click the Freeform Sources tab.

3 In the Source list, select the database instance you want to use for
Freeform SQL reporting.

4 Select Create Freeform SQL report.

5 Click OK.

 The Freeform SQL Editor is available to users who have the “Define
freeform SQL report” and “Create schema objects” privileges.

© 2014 MicroStrategy Inc. The Freeform SQL Editor 39


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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

40 The Freeform SQL Editor © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

The Freeform SQL Editor has the following components:

• Database Instance List—Enables you to select the database instance


that you want to use as the data source for the Freeform SQL report. This
list displays all database instances that you have configured as Freeform
SQL database instances.

• 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.

Accessing the Freeform SQL Editor for Existing Freeform


SQL Reports

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:

1 Open the Freeform SQL report in Design View.

2 In the Report Editor, from the Data menu, select Freeform SQL
Definition.

© 2014 MicroStrategy Inc. The Freeform SQL Editor 41


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

The following image shows this option on the Data menu:


Freeform SQL Report Definition Option

This option enables you to access and modify the Freeform SQL definition for
existing Freeform SQL reports.

42 The Freeform SQL Editor © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

Creating a Freeform SQL Report

After completing this topic, you will be able to:


Create a Freeform SQL report using the Freeform SQL Editor.

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.

2 Define the SQL statement for the report.

3 Map all of the columns in the SELECT clause of the SQL statement.

4 Save the report with the Freeform SQL definition.

The remainder of this topic describes each of these steps in detail.

Selecting the Database Instance


The first step in creating a Freeform SQL report is to select the database
instance that you want to use for the report. This database instance needs to
connect to the data source that stores the data you want to display in the
report.

To select the database instance for a Freeform SQL report:

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.

© 2014 MicroStrategy Inc. Creating a Freeform SQL Report 43


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

Defining the SQL Statement


After you have selected the database instance you want to use for the report,
the next step is to define your own custom SQL to retrieve the desired data. A
well-written SQL query is critical to building successful Freeform SQL
reports. Your query needs to use syntax that is appropriate for whatever data
source you are using. You can take advantage of database-specific syntax and
functions. However, the Freeform SQL Editor does not confirm the validity of
your statement, so you need to ensure that it is correct before using it in a
Freeform SQL report.

44 Creating a Freeform SQL Report © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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.

• You cannot use traditional multipass SQL such as the MicroStrategy


Engine would generate.

 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 execute stored procedures in your SQL statement.

• You can use pre- and post-SQL statements (report-level VLDB properties)
in conjunction with a Freeform SQL report.

 For more information about using derived and common table


expressions and stored procedures to create more complex SQL
queries, see the “Advanced Topics for Freeform SQL Reports” lesson
starting on page 127.

To define the SQL statement for 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.

© 2014 MicroStrategy Inc. Creating a Freeform SQL Report 45


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

The following image shows the SQL statement for the Freeform SQL report:
SQL Statement for Freeform SQL Report

This SQL statement does the following:

• Selects the customer names and education levels

• Aggregates the revenue for each of the selected customers

• 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.

Mapping the Columns


After you define the SQL statement for the report, the next step is to map the
columns that correspond to your custom SQL. You must map each column
that is referenced in the SELECT clause of the SQL statement. You must map
columns in the order in which they appear in the SELECT clause.

46 Creating a Freeform SQL Report © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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.

 You cannot use Freeform SQL objects in standard reports.


You can map attribute columns in your SQL statement to any of the
following:

• Existing attributes in the project

• Existing Freeform SQL attribute objects

• New Freeform SQL attribute objects 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:

• Existing Freeform SQL metric objects

• New Freeform SQL metric objects that you create

 You cannot map fact columns to existing project metrics.


Object names do not need to match the names of the columns in your SQL
statement. Because the object names are used in the report display, you
should name them in accordance with how you want them to display in the
report result.

© 2014 MicroStrategy Inc. Creating a Freeform SQL Report 47


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

To map attribute columns for a Freeform SQL report using existing project
attributes:

1 In the Freeform SQL Editor, in the Object Browser, browse to the


attribute that you want to use.

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.

 You can also double-click the attribute form to add it to the


Mapping pane. You 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 attribute columns for a Freeform SQL report using existing Freeform
SQL attributes:

1 In the Freeform SQL Editor, in the Object Browser, browse to the


Freeform Objects folder.

 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.

 You can also double-click the attribute form to add it to the


Mapping pane. You 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.

48 Creating a Freeform SQL Report © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

To map attribute columns for a Freeform SQL report by creating new Freeform
SQL attributes:

1 In the Freeform SQL Editor, in the Object Browser, browse to the


Freeform Objects folder.

2 In the Freeform Objects folder, double-click <Add New Attribute Form>.

 This action creates a new attribute column in the Mapping pane.


3 In the Mapping pane, in the Object box, type the name of the attribute.

 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:

1 In the Freeform SQL Editor, in the Object Browser, browse to the


Freeform Objects folder.

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:

1 In the Freeform SQL Editor, in the Object Browser, browse to the


Freeform Objects folder.

2 In the Freeform Objects folder, double-click <Add New Metric>.

© 2014 MicroStrategy Inc. Creating a Freeform SQL Report 49


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

 This action creates a new metric column in the Mapping pane.


3 In the Mapping pane, in the Object box, type the name of the metric.

 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 Customer FFSQL attribute is named to distinguish it from the


existing Customer project attribute. In any of the course examples,
when “FFSQL” follows an attribute name, it is being used to
differentiate between Freeform SQL attributes and existing project
attributes.

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:

• Customer ID and DESC (correlates to the customer name)

50 Creating a Freeform SQL Report © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

• Customer Education ID and DESC

• 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.

Benefits of Mapping Attribute Columns to Project Attributes

Below are the benefits of mapping attribute columns in the SQL statement
pane to existing project attributes:

• You can join data from different datasets in a Report Services


document based on a common project attribute.

 For more information on using Freeform SQL reports in Report


Services documents, see “Using Freeform SQL Reports in
Documents” starting on page 74.

• You can add/insert element list prompts in a Freeform SQL report


based on existing project attributes.

 For more information on creating element list prompts, see the


“Prompts in Freeform SQL Reports” lesson starting on page 97.

• You can apply security filters that are based on project attributes to
Freeform SQL reports.

 For more information on using security filters with Freeform SQL


reports, see the “Security for Freeform SQL Reports” lesson
starting on page 187.

Saving the Freeform SQL Report


After you select a database instance, enter the SQL statement, and map the
appropriate columns, you have finished creating the Freeform SQL definition
for the report. You are now ready to close the Freeform SQL Editor. To close
the Freeform SQL Editor, click OK.

© 2014 MicroStrategy Inc. Creating a Freeform SQL Report 51


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

52 Creating a Freeform SQL Report © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

You can make any necessary changes to the template layout before saving the
report, including common manipulations such as the following:

• Pivoting the objects in the template

• 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.

© 2014 MicroStrategy Inc. Creating a Freeform SQL Report 53


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

54 Creating a Freeform SQL Report © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

Managed Objects

After completing this topic, you will be able to:


Describe the purpose of managed objects and work with them in the context
of Freeform SQL reports.

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.

What Is A Managed Object?


A managed object is any MicroStrategy object that is managed by the system
and stored in a special system folder that is not visible to users. A variety of
objects are classified as managed objects, including all Freeform SQL objects.
Therefore, any new object that you create within a Freeform SQL report, like
an attribute or a metric, is created as a managed object.

 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.

© 2014 MicroStrategy Inc. Managed Objects 55


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

You can determine if an object is a managed object by viewing its properties.

To view the properties of a Freeform SQL object:

1 In the Freeform SQL Editor, in the Object Browser, browse to the


Freeform Objects folder.

2 In the Freeform Objects folder, right-click the desired object and select
Properties.

3 In the Properties window, in the General category, view the Location


information.

56 Managed Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

Rather than displaying a folder location, the location information for a


managed object indicates that it is managed by the system. The following
image shows the properties for the Customer Education attribute:
Customer Education Attribute Properties

Notice that the Location field displays “Managed by the system”.

Viewing Managed Objects


Since managed objects are stored in a special system folder that is not visible,
you cannot view them by browsing project folders. Instead, you can view
managed Freeform SQL objects using the Freeform SQL Editor. As you have
already seen, whenever you open the Freeform SQL Editor for any Freeform
SQL report and browse to the Freeform Objects folder, you can view all the
Freeform SQL attributes and metrics that have been created.

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.

© 2014 MicroStrategy Inc. Managed Objects 57


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

To view managed objects using the search function:

1 In MicroStrategy Developer, on the Tools menu, select Search for


Objects.

2 In the Search for Objects window, on the Tools menu, select Options.

3 In the Search Options window, select the Display Managed Objects


check box.

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.

7 Click Find Now.

 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.

58 Managed Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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.

© 2014 MicroStrategy Inc. Managed Objects 59


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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”.

Editing Managed Objects


You can edit certain aspects of managed attribute and metric objects. You can
access the Attribute Editor or Metric Editor for a managed object either from
the Report Editor or from the Search for Objects window.

60 Managed Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

To access the Attribute Editor or Metric Editor for a managed object:

1 In the Report Editor, in Design or Grid View, on the template, right-click


the attribute or metric that you want to edit and select Edit.

 If you see a message window, click OK.


OR

Perform a search for managed objects.

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.

© 2014 MicroStrategy Inc. Managed Objects 61


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

You cannot assign levels, conditions, or transformations to a Freeform SQL


metric. Also, any metric formatting at the report level overrides any
formatting you specify at the metric level.

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.

62 Managed Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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.

Deleting Managed Objects


When you delete a Freeform SQL report, this action does not delete the
Freeform SQL attributes and metrics that are used in the report, even if those
managed objects are not used in other reports. If you know that you have
managed objects that you are not using, you can manually delete them from
the Search for Objects window.

To delete a managed object:

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.

© 2014 MicroStrategy Inc. Managed Objects 63


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

To delete all of the unused managed objects associated with a Freeform SQL
database instance:

1 In MicroStrategy Developer, in the appropriate project, delete all of the


Freeform SQL reports that use the Freeform SQL database instance.

2 In MicroStrategy Developer, right-click the project and select Project


Configuration.

3 In the Project Configuration window, in the Categories list, expand the


Database instances category.

4 In the SQL Data warehouses subcategory, under Available Data Mart,


Query Builder, Freeform and non-primary warehouse database instances,
clear the database instance that you want to remove from the project as a
Freeform SQL database instance.

5 In the message window, click Yes.

 This window warns you that you are removing the Freeform SQL
schema object that is associated with the database instance.

6 In the Project Configuration window, click OK.

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.

8 In MicroStrategy Developer, in the appropriate project source, expand the


Administration icon.

9 Expand the System Administration icon and select Project.

10 In the Object Viewer, right-click the project, point to Administer Project,


and select Delete unused managed objects.

 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.

64 Managed Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

Filters and Freeform SQL Reports

After completing this topic, you will be able to:


Describe how filter conditions are included in Freeform SQL reports.

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:

© 2014 MicroStrategy Inc. Filters and Freeform SQL Reports 65


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

SUM(c.REVENUE) >= 5000


This condition filters the report. The result set includes only customers with
revenue that is greater than or equal to $5,000. This condition is equivalent
to creating a set qualification based on the value of the Revenue metric.

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

The WHERE clause includes the following conditions:


d.MARITAL_STS_ID = 1 and
e.CUST_AGE_RNG_ID = 2
These conditions filter the report. The result set includes only customers with
a marital status of 1 (Single) and an age range of 2 (21 to 40). These
conditions are the equivalent to creating two attribute qualifications, one
based on marital status and another on customer age.

66 Filters and Freeform SQL Reports © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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.

 Ascananalsoalternative to adding filtering conditions directly to the SQL, you


apply view filters to a Freeform SQL report to limit the data
that is displayed. View filter functionality is available only if you have
MicroStrategy OLAP Services.

© 2014 MicroStrategy Inc. Filters and Freeform SQL Reports 67


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Drilling on Freeform SQL Reports

After completing this topic, you will be able to:


Describe the drilling behavior of Freeform SQL reports.

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.

 Drilling on Freeform SQL reports requires you to have MicroStrategy


OLAP Services. Without MicroStrategy OLAP Services, you cannot use
Intelligent Cubes, which provide the drilling capability for Freeform
SQL reports. For more information on MicroStrategy OLAP Services,
see the MicroStrategy Developer: Reporting Essentials course.

68 Drilling on Freeform SQL Reports © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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.

To illustrate drilling behavior, consider the following Freeform SQL report:


Freeform SQL Report - Drilling Example

This report contains three attributes—Customer FFSQL, Customer City


FFSQL, and Customer Gender FFSQL. The Customer FFSQL attribute is in
the Report Objects window, but it is not on the template. All three of these
attributes are Freeform SQL attributes.

© 2014 MicroStrategy Inc. Drilling on Freeform SQL Reports 69


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

70 Drilling on Freeform SQL Reports © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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 report now contains four attributes—Customer, Customer City,


Customer Gender FFSQL, and Month. The Customer, Customer Gender
FFSQL, and Month attributes are in the Report Objects window, but they are
not on the template. The Customer and Customer City attributes are now
defined using existing project attributes rather than Freeform SQL attributes.
The Month attribute also maps to an existing project attribute. The Customer
Gender FFSQL attribute is the only Freeform SQL attribute in the report.

© 2014 MicroStrategy Inc. Drilling on Freeform SQL Reports 71


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

72 Drilling on Freeform SQL Reports © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

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.

© 2014 MicroStrategy Inc. Drilling on Freeform SQL Reports 73


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Using Freeform SQL Reports in Documents

After completing this topic, you will be able to:


Describe how you can use Freeform SQL reports in Report Services
documents.

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

74 Using Freeform SQL Reports in Documents © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Creating Freeform SQL Reports 2

In this example, the document consists of the following three reports:

• Freeform SQL report that executes against a SQL Server database

• Standard MicroStrategy report that executes against the project’s primary


DB2 data warehouse

• A second Freeform SQL report that executes against an Oracle database

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.

© 2014 MicroStrategy Inc. Using Freeform SQL Reports in Documents 75


2 Creating Freeform SQL Reports MicroStrategy Freeform SQL Essentials


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 alternatively add filtering conditions by applying view filters to a


Freeform SQL report if you have MicroStrategy OLAP Services.

• Drilling on Freeform SQL reports require you to have MicroStrategy


OLAP services since drilling is limited to attributes contained within the
personal Intelligent Cube.

• You can use Freeform SQL reports to build a Report Services document.

76 Lesson Summary © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2


Exercises
You should complete the following exercises using the MicroStrategy Tutorial
project, which is found in the MicroStrategy Analytics Modules project
source.

Exercise 2.1: Creating a New Folder

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Create a new folder

1 In MicroStrategy Developer, in the MicroStrategy Tutorial project, select


the My Personal Objects folder.

2 In the My Personal Objects folder, double-click the My Reports folder.

3 In the Object Viewer, right-click an empty area, point to New, and select
Folder.

4 Type Freeform SQL Exercises as the folder name.

© 2014 MicroStrategy Inc. Exercises 77


2 Exercises MicroStrategy Freeform SQL Essentials

Exercise 2.2: Configuring a New Freeform SQL Database


Instance

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Create a database instance

1 In the MicroStrategy Analytics Modules project source, expand the


Administration icon.

2 Expand the Configuration Managers icon.

3 Right-click Database Instances, point to New, and select Database


Instance.

4 In the Database Instances window, on the General tab, in the Database


instance name box, type Customer Analysis FFSQL as the database
instance name.

5 In the Database connection type drop-down box, select Microsoft SQL


Server 2008.

6 Click New.

7 In the Database Connections window, on the General tab, in the Database


connection name box, type Customer Analysis FFSQL as the database
connection name.

8 Under Local system ODBC data sources, select FFSQL_CUST_WH.

78 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

9 Under Default database login name, select sa.

 Create the sa login name - with login id sa and password Training


- if it is not already created.

10 Click OK.

11 In the Database Instances window, under Database connection (default),


select Customer Analysis FFSQL.

12 Click OK.

Configure the database instance for Freeform SQL reporting

13 In the MicroStrategy Analytics Modules project source, right-click the


MicroStrategy Tutorial project and select Project Configuration.

14 In the Project Configuration window, in the Categories list, expand the


Database instances category.

15 In the SQL Data warehouses subcategory, under Available Data Mart,


Query Builder, Freeform and non-primary warehouse database instances,
select Customer Analysis FFSQL.

16 In the message window, click No.

17 In the Project Configuration window, click OK.

Exercise 2.3: Creating a Basic Freeform SQL Report

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.

© 2014 MicroStrategy Inc. Exercises 79


2 Exercises MicroStrategy Freeform SQL Essentials

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Open the Freeform SQL Editor

1 In the Freeform SQL Exercises folder, right-click an empty area in the


Object Viewer, point to New, and select Report.

2 In the New Grid window, click the Freeform Sources tab.

3 In the Source list, select Customer Analysis FFSQL.

4 Click Create Freeform SQL report radio button.

80 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

5 Click OK.

Enter the SQL statement

6 Open Windows Explorer and navigate to the C:\MSTR\FFSQL folder.

7 Double-click the Exercises SQL Word document.

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.

Map the columns

10 In the Freeform SQL Editor, in the Object Browser, in the Freeform


Objects folder, double-click <Add New Attribute Form>.

11 In the Mapping pane, for Column 1, in the Object box, type Customer
FFSQL as the attribute name. Leave the Form as ID.

12 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

13 In the Mapping pane, for Column 2, in the Object box, type Customer
FFSQL as the attribute name.

14 In the Form drop-down box, select DESC.

15 Double-click <Add New Attribute Form>.

© 2014 MicroStrategy Inc. Exercises 81


2 Exercises MicroStrategy Freeform SQL Essentials

16 In the Mapping pane, for Column 3, in the Object box, type Month
FFSQL as the attribute name. Leave the Form as ID.

17 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

18 In the Mapping pane, for Column 4, in the Object box, type Month
FFSQL as the attribute name.

19 In the Form drop-down box, select DESC.

20 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

21 In the Mapping pane, for Column 5, in the Object box, type Product as
the attribute name. Leave the Form as ID.

22 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

23 In the Mapping pane, for Column 6, in the Object box, type Product as
the attribute name.

24 In the Form drop-down box, select DESC.

25 In the Object Browser, in the Freeform Objects folder, double-click


Revenue.

26 Double-click Profit.

The completed column mapping should look 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 and drop the columns to change the order
or right-click the columns and use the Move Up or Move Down
options.

82 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

Save the Freeform SQL definition

27 Click OK.

Format the metrics

28 In the Report Editor, in Design View, right-click the Revenue metric,


point to Formatting, point to All Metrics, and select Values.

29 In the Format Cells window, on the Number tab, under Category, select
Currency.

30 Click OK.

Save and run the report

31 Save the report in the Freeform SQL Exercises folder as Q4 2011


Customer Purchase Analysis.

32 Run the report.

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.

Exercise 2.4: Manipulating a Basic Freeform SQL Report

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:

• Move the Month FFSQL attribute to the page-by field

• Add a Total subtotal

 You can use the default settings for the Total subtotal.
• Change the autostyle for the report to Finance

© 2014 MicroStrategy Inc. Exercises 83


2 Exercises MicroStrategy Freeform SQL Essentials

• Merge the row header cells

• Turn off banding on the report

• Change the background color for the row values to Light Green

• Remove the Profit metric from the grid

• 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.

 Do not save over the original report.


Run the report. With October 2011 selected in the page-by field, the first part
of the result set should look like the following:

You can use the detailed instructions if you want help.

84 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

Detailed Instructions

Move the Month FFSQL attribute to the page-by field

1 On the Q4 2011 Customer Purchase Analysis report, right-click the Month


FFSQL attribute, point to Move, and select To Page-by.

Add subtotals

2 On the Data menu, select Subtotals.

3 In the Subtotals window, on the Definition tab, under Available subtotals,


select the Total check box.

4 Click OK.

Change the report format

5 On the Grid menu, point to Autostyle Selected and select Finance.

6 On the Grid menu, select Merge Row Header Cells.

7 On the Grid menu, select Options.

8 In the Grid Options window, on the General tab, under Banding, select No
banding.

9 Click OK.

10 On the Format menu, point to Rows and select Values.

11 In the Format Cells window, click the Background tab.

12 On the Background tab, in the Background style drop-down box, ensure


that Solid is selected.

13 In the Fill color drop-down box, select Light Green.

14 Click OK.

Remove the Profit metric from the grid

15 Right-click the Profit metric and select Remove from Grid.

16 In the message window, click Yes.

© 2014 MicroStrategy Inc. Exercises 85


2 Exercises MicroStrategy Freeform SQL Essentials

Sort the report data

17 On the Data menu, select Advanced Sorting.

18 In the Sorting window, on the Rows tab, click Add.

19 Under Currently defined sorts, in the Sort By drop-down box, select


Revenue.

20 In the Order drop-down box, select Descending.

21 Select the Sort metrics hierarchically using check box.

22 In the drop-down box, select Total.

23 Click OK.

24 Compare your results to the expected report in the Overview section at the
beginning of this exercise.

Save the report

25 Save the report in the Freeform SQL Exercises folder as Formatted Q4


2011 Customer Purchase Analysis.

 Do not save over the original report.


26 Close the report.

Exercise 2.5: Configuring a Second Freeform SQL Database


Instance

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.

You can use the detailed instructions if you want help.

86 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

Detailed Instructions

Create a database instance

1 In the MicroStrategy Analytics Modules project source, expand


Administration.

2 Expand the Configuration Managers.

3 Right-click Database Instances, point to New, and select Database


Instance.

4 In the Database Instances window, on the General tab, in the Database


instance name box, type Employee Analysis FFSQL as the database
instance name.

5 In the Database connection type drop-down box, select Microsoft SQL


Server 2008.

6 Click New.

7 In the Database Connections window, on the General tab, in the Database


connection name box, type Employee Analysis FFSQL as the database
connection name.

8 Under Local system ODBC data sources, select FFSQL_EMP_WH.

9 Under Default database login name, select sa.

10 Click OK.

11 In the Database Instances window, under Database connection (default),


select Employee Analysis FFSQL.

12 Click OK.

 If a message window displays, click Yes.


Configure the database instance for Freeform SQL reporting

13 In the MicroStrategy Analytics Modules project source, right-click the


MicroStrategy Tutorial project and select Project Configuration.

14 In the Project Configuration window, in the Categories list, expand the


Database instances category.

© 2014 MicroStrategy Inc. Exercises 87


2 Exercises MicroStrategy Freeform SQL Essentials

15 In the SQL Data warehouses subcategory, under Available Data Mart,


Query Builder, Freeform and non-primary warehouse database instances,
select Employee Analysis FFSQL.

16 In the message window, click No.

17 In the Project Configuration window, click OK.

Exercise 2.6: Creating a Freeform SQL Report Using the Second


Database Instance

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.

Save the report in the Freeform SQL Exercises folder as Employee


Performance Analysis.

88 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Open the Freeform SQL Editor

1 In the Freeform SQL Exercises folder, right-click an empty area in the


Object Viewer, point to New, and select Report.

2 In the New Grid window, click the Freeform Sources tab.

3 In the Source list, select Employee Analysis FFSQL.

4 With the Create Freeform SQL report radio button selected, click OK.

© 2014 MicroStrategy Inc. Exercises 89


2 Exercises MicroStrategy Freeform SQL Essentials

Enter the SQL statement

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.

Map the columns

7 In the Freeform SQL Editor, in the Object Browser, in the Freeform


Objects folder, double-click <Add New Attribute Form>.

8 In the Mapping pane, for Column 1, in the Object box, type Employee
Location as the attribute name.

9 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

10 In the Mapping pane, for Column 2, in the Object box, type Employee
Location as the attribute name.

11 In the Form drop-down box, select DESC.

12 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

13 In the Mapping pane, for Column 3, in the Object box, type Employee
FFSQL as the attribute name.

14 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

15 In the Mapping pane, for Column 4, in the Object box, type Employee
FFSQL as the attribute name.

90 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

16 In the Form drop-down box, select DESC.

17 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

18 In the Mapping pane, for Column 5, in the Object box, type Average
Performance Score as the metric name.

The completed column mapping should look 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 and drop the columns to change the order
or right-click the columns and use the Move Up or Move Down
options.

Save the Freeform SQL definition

19 Click OK.

Format the metrics

20 In the Report Editor, in Design View, right-click the Average


Performance Score metric, point to Formatting, and select Average
Performance Score Values.

21 In the Format Cells window, click the Number tab.

22 On the Number tab, under Category, select Fixed.

23 Click OK.

Save and run the report

24 Save the report in the Freeform SQL Exercises folder as Employee


Performance Analysis.

25 Run the report.

© 2014 MicroStrategy Inc. Exercises 91


2 Exercises MicroStrategy Freeform SQL Essentials

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.

Exercise 2.7: Modifying the Filter Conditions of a Freeform SQL


Report

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.

 Do not save over the original report.

92 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Switch to Design View on the Freeform SQL report

1 On the Employee Performance Analysis report, on the View menu, select


Design View.

2 In Design View, on the Data menu, select Freeform SQL Definition.

Modify the SQL statement

3 In the Freeform SQL Editor, in the SQL Statement pane, delete the
original SQL statement.

© 2014 MicroStrategy Inc. Exercises 93


2 Exercises MicroStrategy Freeform SQL Essentials

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.

5 Close the Exercises SQL Microsoft Word document.

6 In the Freeform SQL Editor, click OK.

Save and run the report

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.

 Do not save over the original report.


8 Run the report.

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.

94 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 2

Follow-up Questions

1 Can you drill on the Employee FFSQL attribute in this report? Why or
why not?

_______________________________________

_______________________________________

_______________________________________

_______________________________________

2 If you mapped the EMPLOYEE_ID and EMPLOYEE_DESC columns in


the SQL statement to the Employee attribute in the MicroStrategy
Tutorial project, would you be able to drill up from the Employee
attribute to the Region attribute? Why or why not?

_______________________________________

_______________________________________

_______________________________________

_______________________________________

Answers to Follow-up Questions

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.

2 If you mapped the EMPLOYEE_ID and EMPLOYEE_DESC columns in


the SQL statement to the Employee project attribute, you could not drill
from this attribute up to the Region attribute since Region is not a part of
the personal Intelligent Cube. In Freeform SQL reports, you can drill on
project attributes to only attributes that are part of the personal
Intelligent Cube.

© 2014 MicroStrategy Inc. Exercises 95


2 Exercises MicroStrategy Freeform SQL Essentials

96 Exercises © 2014 MicroStrategy Inc.


3
PROMPTS IN FREEFORM SQL
REPORTS

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.

© 2014 MicroStrategy Inc. 97


3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Lesson Objectives

After completing this lesson, 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.

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)

98 Lesson Objectives © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Prompts in Freeform SQL Reports 3

Using Prompts in Freeform SQL Reports

After completing this topic, you will be able to:


Describe the types of prompts that you can use in Freeform SQL reports.

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:

• Element list prompts—This type of prompt enables you to select from a


list of attribute elements.

 You can create element list prompts based on project attributes


only, as opposed to managed object attributes.

• Value prompts—This type of prompt enables you to enter a date,


numeric, text, or big decimal value.

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.

© 2014 MicroStrategy Inc. Using Prompts in Freeform SQL Reports 99


3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Creating a Freeform SQL Report with Prompts

After completing this topic, you will be able to:


Add new prompts and insert existing prompts into Freeform SQL reports.
Configure prompts as optional.

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.

• Insert Prompt—This option enables you to select an existing element list


or value prompt in the project.

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

Adding a New Prompt to a Freeform SQL Report


If you do not already have a prompt in your project that you want to use in a
Freeform SQL report, you can create the prompt that you need directly from
the Freeform SQL Editor.

To add a new prompt to a Freeform SQL report:

1 In the Freeform SQL Editor, in the SQL Statement pane, place the cursor
at the location where you want to include the prompt.

 Ifwithyoua want to replace existing information in the SQL statement


prompt, you can select the SQL that you want to replace.

2 On the Edit menu, select Add New Prompt.

 This action opens the Prompt Generation Wizard.


3 In the Prompt Generation Wizard, do one of the following:

If you want to create an element list prompt, select Filter definition


prompt.

OR

If you want to create a value prompt, select Value prompt.

4 Click Next.

5 Configure the prompt as desired.

6 After you have configured the prompt, click Finish.

7 Save the prompt in the desired folder.

 The default location for saving prompts is the Public


Objects\Prompts folder.

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

Inserting an Existing Prompt in a Freeform SQL Report


If you already have a prompt in your project that you want to use in a
Freeform SQL report, you can insert that prompt directly from the Freeform
SQL Editor.

To insert an existing prompt in a Freeform SQL report:

1 In the Freeform SQL Editor, in the SQL Statement pane, place the cursor
at the location where you want to include the prompt.

 Ifwithyoua want to replace existing information in the SQL statement


prompt, you can select the SQL that you want to replace.

2 On the Edit menu, select Insert 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

Using Element List Prompts in a Freeform SQL Report


Element list prompts enable you to select from a list of attribute elements.
The selections that you make determine what data is included in the result
set. The following image shows the definition of a Freeform SQL report that
uses an element list prompt for the Customer Gender attribute in the
WHERE clause:
Freeform SQL Report with Element List Prompt

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.

Using Value Prompts in a Freeform SQL Report


Value prompts enable you to enter a date, numeric, text, or big decimal value.
You can include value prompts in various parts of a SQL statement. The
following image shows the definition of a Freeform SQL report that uses a
value prompt for the Customer City FFSQL attribute in the WHERE clause:
Freeform SQL Report with Value Prompt

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:

select CUSTOMER_ID, CUSTOMER_NAME


from [Select Table]

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

Using Optional Prompts in a Freeform SQL Report


When you create prompts, you can define them as either required or
optional. End users must answer a required prompt to execute a report,
whereas they can choose not to answer an optional prompt and still execute
the report. You can determine whether a prompt is required or optional by
viewing its definition in the Prompt Generation Wizard.

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.

To make SQL prompt dependent:

1 In the Freeform SQL Editor, in the SQL Statement pane, select the SQL
that you want to make prompt dependent.

2 Right-click the selected SQL and select Prompt-dependent SQL.

© 2014 MicroStrategy Inc. Creating a Freeform SQL Report with Prompts 113
3 Prompts in Freeform SQL Reports MicroStrategy Freeform SQL Essentials

The following image shows the Prompt-dependent SQL option:


Prompt-dependent SQL Option

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.

• You must make the corresponding SQL prompt-dependent, if you use


optional prompts in a Freeform SQL report.

116 Lesson Summary © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 3


Exercises
You should complete the following exercises using the MicroStrategy Tutorial
project, which is found in the MicroStrategy Analytics Modules project
source.

Exercise 3.1: Using an Element List Prompt in a Freeform SQL


Report

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.

© 2014 MicroStrategy Inc. Exercises 117


3 Exercises MicroStrategy Freeform SQL Essentials

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Open the Freeform SQL Editor

1 In the Freeform SQL Exercises folder, right-click an empty area in the


Object Viewer, point to New, and select Report.

2 In the New Grid window, click the Freeform Sources tab.

3 In the Sources list, select Customer Analysis FFSQL.

118 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 3

4 With the Create Freeform SQL report radio button selected, click OK.

Enter the SQL statement

5 Open Windows Explorer and navigate to the C:\MSTR\FFSQL folder.

6 In the FFSQL folder, double-click the Exercises SQL Microsoft Word


document.

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:

Map the columns

8 In the Freeform SQL Editor, in the Object Browser, browse to the


Education Level attribute in Schema Objects\Attributes\Customers.

9 Expand the Education Level attribute.

10 Under the Education Level attribute, double-click the ID form.

11 Double-click the DESC form.

12 In the Object Browser, in the Freeform Objects folder, browse to


Customer FFSQL attribute.

13 Expand the Customer FFSQL attribute.

14 Under the Customer FFSQL attribute, double-click the ID form.

15 Double-click the DESC form.

16 In the Object Browser, in the Freeform Objects folder, double-click


Revenue.

© 2014 MicroStrategy Inc. Exercises 119


3 Exercises MicroStrategy Freeform SQL Essentials

The completed column mapping should look 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.

Create and add the prompt to the report

17 In the Freeform SQL Editor, in the SQL Statement pane, in the WHERE
clause, highlight <insert prompt>.

18 On the Edit menu, select Add New Prompt.

19 In the Prompt Generation Wizard, keep Filter definition prompt


selected.

20 Click Next.

21 In the Attribute box, type Education Level.

 This is the project attribute that has been mapped to the


CUST_EDUCATION_ID and CUST_EDUCATION_DESC
columns.

22 Click Next.

23 Keep the default selections and click Next.

24 Under Display properties, in the Title box, enter a title for the prompt.

25 In the Instructions box, enter a description for the prompt.

26 Under Prompt restrictions, select Prompt answer required.

27 Click Finish.

28 In the Save As window, browse to the Freeform SQL Exercises folder.

120 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 3

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 SQL statement should now look like the following:

 The prompt name and the brackets that surround it should display
in pink text.

Save the Freeform SQL definition

32 Click OK.

Format the metric

33 In the Report Editor, in Design View, right-click the Revenue metric,


point to Formatting, and select Revenue Values.

34 In the Format Cells window, on the Number tab, under Category, select
Currency.

35 Click OK.

Save and run the report

36 Save the report in the Freeform SQL Exercises folder as Customer


Purchase Analysis for Selected Customer Education Level.

37 Run the report.

38 When the prompt displays, select Graduate as the prompt answer.

39 Click Finish.

© 2014 MicroStrategy Inc. Exercises 121


3 Exercises MicroStrategy Freeform SQL Essentials

40 Compare your results to the expected report in the Overview section at the
beginning of this exercise.

41 Close the report.

Exercise 3.2: Using a Value Prompt in a Freeform SQL Report

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.

 The Employee Performance Analysis report is located in the


Freeform SQL Exercises folder.

In the Employee Performance Analysis report, you will add a HAVING


clause for the Average Performance Score metric using the Choose a Score
Value prompt. This prompt enables you to select the employees to be
included in the report based on their average performance scores. You should
use an operator that enables you to see employees with average performance
scores greater than or equal to the numeric value you enter. Finally,
because the prompt is optional, you need to make the associated SQL prompt
dependent.

After you have made these changes to the report, save the report in the
Freeform SQL Exercises folder as Prompted Employee Performance
Analysis.

 Do not save over the original report.


Run the report and enter 4.3 as the prompt answer. The result set should look
like the following:

122 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 3

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.

You can use the detailed instructions if you want help.

Detailed Instructions
Open the Freeform SQL report in Design View

1 In the Freeform SQL Exercises folder, right-click the Employee


Performance Analysis report and select Edit.

Open the Freeform SQL Editor

2 In the Report Editor, in Design View, on the Data menu, select Freeform
SQL Definition.

Create and add the prompt to the report

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.

© 2014 MicroStrategy Inc. Exercises 123


3 Exercises MicroStrategy Freeform SQL Essentials

4 Type Having.

5 Press Control + Tab.

6 Type AVG(c.EMP_PRF_SCORE_ID) >=.

The SQL statement should now look like the following:

7 Position the cursor at the end of the HAVING clause.

8 On the Edit menu, click Add New Prompt.

9 In the Prompt Generation Wizard, click Value prompt.

10 Click Next.

11 Select Numeric prompt.

12 Click Next.

13 Under Display properties, in the Title box, enter a title for the prompt.

14 In the Instructions box, enter a description for the prompt.

15 Under Prompt restrictions, ensure that the Prompt answer required


check box is cleared.

16 Click Next.

 You do not need to specify default, minimum, or maximum values.


17 Click Finish.

18 In the Save As window, browse to the Freeform SQL Exercises folder.

19 In the Object name box, type Choose a Score Value as the prompt
name.

124 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 3

20 Click Save.

21 In the message window, click OK.

 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.

Make the associated SQL prompt dependent

22 Select the entire HAVING clause.

23 Right-click the selected SQL and select Prompt-dependent SQL.

The SQL statement should now look like the following:

 The entire HAVING clause should display in pink text.


Save the Freeform SQL definition

24 Click OK.

Save and run the report

25 Save the report in the Freeform SQL Exercises folder as Prompted


Employee Performance Analysis.

 Do not save over the original report.


26 Run the report.

27 When the prompt displays, type 4.3 as the prompt answer.

28 Click Finish.

29 Compare your results to the first expected report in the Overview section
at the beginning of this exercise.

© 2014 MicroStrategy Inc. Exercises 125


3 Exercises MicroStrategy Freeform SQL Essentials

Re-execute the report

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.

33 Compare your results to the second expected report in the Overview


section at the beginning of this exercise.

34 Close the report.

126 Exercises © 2014 MicroStrategy Inc.


4
ADVANCED TOPICS FOR
FREEFORM SQL REPORTS

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.

© 2014 MicroStrategy Inc. 127


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Lesson Objectives

After completing this lesson, you will be able to:


Create Freeform SQL reports that use derived and common table
expressions, stored procedures, and non-relational data sources.

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)

128 Lesson Objectives © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

Using Derived and Common Table Expressions

After completing this topic, you will be able to:


Define derived and common table expressions and create Freeform SQL
reports that use derived and common table expressions.

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.

 You can also simulate multiple passes of SQL by creating a stored


procedure and then executing it using a Freeform SQL report. You will
learn about using stored procedures with Freeform SQL reports later
in this lesson.

 Another alternative for processing multiple passes of SQL is to use the


VLDB Pre and Post Statement properties. For more information on
using these VLDB properties, see the MicroStrategy Engine Essentials
course.

Derived Table Expressions


A derived table expression is a SELECT statement that appears in the FROM
clause of a query. The syntax for a derived table expression looks like the
following:

© 2014 MicroStrategy Inc. Using Derived and Common Table Expressions 129
4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

select ColA, ColB, ColD


from (select ColA, ColB, SUM(ColC) as ColD
from TableA
group by ColA, ColB)
where ColD > 1000
In this example, notice that the outer FROM clause contains a SELECT
statement that extracts information from a table. This result is then used in
the outer query.

Common Table Expressions


A common table expression is a SELECT statement that appears in the WITH
clause of a query. The syntax for a common table expression looks like the
following:
with CTE1 as (select ColA, ColB, SUM(ColC) as
ColD
from TableA
group by ColA, ColB)
select ColA, ColB, ColD
from CTE1
where ColD > 1000
In this example, notice that the WITH clause contains a SELECT statement
that extracts information from a table. This result is then used in the outer
query.

Derived Versus Common Table Expressions


The processes for using derived and common table expressions to create a
Freeform SQL report differ only in syntax. Both types of expressions are
equally valid means of producing subqueries. However, support for each type
of expression does vary based on the database platform that you are using.
For example, support for common table expressions is not as widely available
as for derived table expressions.

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.

Creating a Freeform SQL Report Using Derived Table


Expressions
Often, report queries require more than one simple pass of SQL. For
example, consider the following report:
Employee Overtime Percent Contribution Example

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.

Finally, the outermost SELECT clause retrieves the information to display on


the report, including the attribute descriptions, and calculates the Percent
Contribution to Region Overtime metric.ogy

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

Using Stored Procedures

After completing this topic, you will be able to:


Create Freeform SQL reports that use stored procedures.

If you want to execute multiple passes of SQL in a Freeform SQL report,


another alternative to using derived and common table expressions is to
create stored procedures. A stored procedure is a collection of compiled SQL
statements that you can run against a database by executing the stored
procedure.

Most database environments contain stored procedures that have been


created to accomplish routine tasks or queries. When executing such queries,
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.

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.

Stored procedures provide three important advantages:

• Generally, the database administrator (or whoever created the stored


procedure) has optimized the SQL in a stored procedure to run as
efficiently as possible.
• Because stored procedures are compiled, the database already has an
execution plan for them. The database does not have to compile an
execution plan each time you run stored procedures as it does for
individual queries. Therefore, the database can more efficiently process
stored procedures.

• Stored procedures offer the ability to create Freeform SQL reports by


using multiple passes of SQL and storing intermediate results in
temporary tables, which generally yield simpler SQL than using
subqueries.

© 2014 MicroStrategy Inc. Using Stored Procedures 135


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Creating a Freeform SQL Report Using Stored Procedures


You can create a Freeform SQL report that retrieves the same employee
overtime contribution information by creating and executing a stored
procedure. Before you can define the SQL for the Freeform SQL report, you
first have to create a stored procedure in the database that contains the data
you want to retrieve.

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.

136 Using Stored Procedures © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

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 third statement retrieves the information to display on the report,


including the attribute descriptions, and calculates the Percent Contribution
to Region Overtime metric. It consolidates information from several database
tables as well as the two temporary tables that contain the intermediate result
sets from the first two passes of SQL.

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.

© 2014 MicroStrategy Inc. Using Stored Procedures 137


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 - 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.

138 Using Stored Procedures © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

Accessing Non-relational Data Sources

After completing this topic, you will be able to:


Create Freeform SQL reports using Microsoft Excel files and text files.

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.

Using Microsoft Excel Files for Freeform SQL Reports


With Freeform SQL reports, you can access information directly from a
Microsoft Excel file. To access a Microsoft Excel file as a data source, you
need to perform the following steps:

1 Prepare the Microsoft Excel file by creating tables.

2 Create a DSN that points to the Microsoft Excel file.

3 Create a database instance that points to the DSN and configure it as a


Freeform SQL database instance.

4 Create a Freeform SQL report that executes against the Microsoft Excel
database instance.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 139


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Preparing the Microsoft Excel File

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.

To create tables in a Microsoft Excel file:

1 Open the Microsoft Excel file.

2 Ensure that all of the data columns have column headers that use the
appropriate syntax.

 You cannot have spaces in a column header name (for example,


Customer_ID, not Customer ID). Also, if a column header name is
alphanumeric, it must start with letters, not numbers (for example,
Q2013, not 2013Q).

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.

6 In the warning window, click Yes.

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.

140 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

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.

10 Save the Microsoft Excel file.

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.

12 In the Microsoft Office Excel Compatibility Checker warning, click


Continue.

 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.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 141


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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:

select [‘Customer Data$’].Customer_ID,[‘Customer


Data$’].Customer_Name

from [‘Customer Data$’]

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.

Creating a DSN for the Microsoft Excel File

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.

To create a DSN for a Microsoft Excel file:

1 On the Start menu, select All Programs, select MicroStrategy Tools, and
select Connectivity Wizard.

2 In the MicroStrategy Connectivity Wizard welcome window, click Next.

3 In the Driver Selection window, select Other Relational Databases.

4 Click Next.

5 In the Driver Selection window, select Microsoft Excel Driver(*.xls).

142 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

6 Click Next.

7 In the ODBC Microsoft Excel Setup window, in the Data Source Name
box, type a name for the DSN.

8 Click Select Workbook.

9 In the Select Workbook window, browse to and select the desired


Microsoft Excel file.

10 Click OK.

11 In the ODBC Microsoft Excel Setup window, click OK.

12 In the DSN created window, 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.

Configuring a Database Instance for the Microsoft Excel 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 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.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 143


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

 MicroStrategy recommends that you use Microsoft Excel


2000/2003 as the 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.

144 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

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.

 For more information on configuring database instances for Freeform


SQL reporting, see “Configuring a Database Instance for Freeform
SQL” starting on page 37.

The following image shows the Microsoft Excel database instance configured
as a Freeform SQL database instance:
Microsoft Excel Database Instance Configured for Freeform SQL

The Excel Tables FFSQL database instance, which points to the


Cust_Prod_Txn_Tables.xls file, is selected as a Freeform SQL database
instance in the Project Configuration window.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 145


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Creating a Freeform SQL Report Using the Microsoft Excel


File

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.

146 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

The following image shows the first part of the result set for this report:
Freeform SQL Report Result Set - Microsoft Excel File

The report displays the number of transactions for each customer.

Using Text Files for Freeform SQL Reports


With Freeform SQL reports, you can also access information directly from
text files. To access a text file as a data source, you need to perform the
following steps:

1 Prepare the text file.

2 Create a DSN that points to the text file.

3 Create a database instance that points to the DSN and configure it as a


Freeform SQL database instance.

4 Create a Freeform SQL report that executes against the text database
instance.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 147


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

 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.

Preparing the Text File

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.

148 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

Creating a DSN for the Text File

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:

1 On the Start menu, select Settings, and select Control Panel.

2 In the Control Panel window, double-click Administrative Tools.

3 In the Administrative Tools window, double-click Data Sources (ODBC)


Shortcut.

4 In the ODBC Data Source Administrator window, click the System DSN
tab.

5 On the System DSN tab, click Add.

6 In the Create New Data Source window, select MicroStrategy ODBC


Driver for Text.

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.

10 Click the Advanced tab.

11 On the Advanced tab, click Define.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 149


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

 For example, if the name of the text file is


Account_Information.txt, you could use LU_ACCOUNT_INFO as
the table name. The table name cannot contain any spaces. You use
this table name in the SQL statement for any Freeform SQL reports
that execute against 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.

150 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

20 In the Define File window, click Cancel.

21 In the ODBC Text Driver Setup window, click OK.

22 In the ODBC Data Source Administrator window, click OK.

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.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 151


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

Configuring a Database Instance for 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.

152 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

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.

 For more information on configuring database instances for Freeform


SQL reporting, see “Configuring a Database Instance for Freeform
SQL” starting on page 37.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 153


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

The following image shows the text database instance configured as a


Freeform SQL database instance:
Text Database Instance Configured for Freeform SQL

The Text File FFSQL database instance, which maps to the


Account_Information.txt file, is selected as a Freeform SQL database
instance in the Project Configuration window.

154 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4

Creating a Freeform SQL Report Using the Text File

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.

© 2014 MicroStrategy Inc. Accessing Non-relational Data Sources 155


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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.

156 Accessing Non-relational Data Sources © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Advanced Topics for Freeform SQL Reports 4


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.

• A derived table expression is a SELECT statement that appears in the


FROM clause of a query.

• A common table expression is a SELECT statement that appears in the


WITH clause of a query.

• 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.

© 2014 MicroStrategy Inc. Lesson Summary 157


4 Advanced Topics for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

158 Lesson Summary © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4


Exercises
You should complete the following exercises using the MicroStrategy Tutorial
project, which is found in the MicroStrategy Analytics Modules project
source.

Exercise 4.1: Creating a Freeform SQL Report with Derived


Table Expressions

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:

• Count of Customers Age 21 to 40

• Percent of Customers Age 21 to 40 (in each customer city)

• Count of Customers Age 41 to 60

• Percent of Customers Age 41 to 60 (in each customer city)

 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.

 Microsoft SQL Server automatically processes the division of counted


columns as integers, which yields 0 as the value for all percentages. To
resolve this issue, you need to convert each count to float data type.
The Detailed Instructions contain the syntax for performing this
conversion.

© 2014 MicroStrategy Inc. Exercises 159


4 Exercises MicroStrategy Freeform SQL Essentials

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Open the Freeform SQL Editor

1 In the Freeform SQL Exercises folder, right-click an empty area in the


Object Viewer, point to New, and select Report.

2 In the New Grid window, click the Freeform Sources tab.

3 In the Source list, select Customer Analysis FFSQL.

4 With the Create Freeform SQL report radio button selected, click OK.

Enter the SQL statement

5 Open Windows Explorer and navigate to the C:\MSTR\FFSQL folder.

6 In the FFSQL folder, double-click the Exercises SQL Microsoft Word


document.

160 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

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.

Map the columns

9 In the Freeform SQL Editor, in the Object Browser, in the Freeform


Objects folder, double-click <Add New Attribute Form>.

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.

11 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

12 In the Mapping pane, for Column 2, in the Object box, type Customer
City FFSQL as the attribute name.

13 In the Form drop-down box, select DESC.

14 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

© 2014 MicroStrategy Inc. Exercises 161


4 Exercises MicroStrategy Freeform SQL Essentials

15 In the Mapping pane, for Column 3, in the Object box, type Count of
Customers Age 21 to 40 as the metric name.

16 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

17 In the Mapping pane, for Column 4, in the Object box, type Percent of
Customers Age 21 to 40 as the metric name.

18 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

19 In the Mapping pane, for Column 5, in the Object box, type Count of
Customers Age 41 to 60 as the metric name.

20 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

21 In the Mapping pane, for Column 6, in the Object box, type Percent of
Customers Age 41 to 60 as the metric name.

The completed column mapping should look like the following:

Save the Freeform SQL definition

22 Click OK.

Format the metrics

23 In the Report Editor, in Design View, right-click the Percent of


Customers Age 21 to 40 metric, point to Formatting, and select
Percent of Customers Age 21 to 40 Values.

24 In the Format Cells window, on the Number tab, under Category, select
Percent.

25 Click OK.

162 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

26 In the Report Editor, in Design View, right-click the Percent of


Customers Age 41 to 60 metric, point to Formatting, and select
Percent of Customers Age 41 to 60 Values.

27 In the Format Cells window, on the Number tab, under Category, select
Percent.

28 Click OK.

Save and run the report

29 Save the report in the Freeform SQL Exercises folder as Targeted


Customer Age Range Analysis.

30 Run the report.

31 Compare your results to the expected report in the Overview section at the
beginning of this exercise.

32 Close the report.

Exercise 4.2: Creating a Freeform SQL Report with a Stored


Procedure

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:

• Aggregate (sum) the revenue for each product

• Aggregate (sum) the revenue for each product group

© 2014 MicroStrategy Inc. Exercises 163


4 Exercises MicroStrategy Freeform SQL Essentials

• Aggregate (sum) the revenue across all products

• Return the following information to display in a report:

– Product groups and their associated products

– Revenue for each product

– Percent contribution of each product’s revenue to the entire revenue


for its product group (needs to be calculated)

– Percent contribution of each product’s revenue to the revenue for all


products (needs to be calculated)

Name the stored procedure spPROD_CONTR.

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

• Percent Contribution of Product to Product Group Revenue

• Percent Contribution of Product to All 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.

164 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Create the stored procedure

1 On the Start menu, select All Programs, select Microsoft SQL Server
2008 R2, and select SQL Server Management Studio.

2 In the Connect to Server window, in the Server name drop-down box,


select the name of your server.

3 In the Authentication drop-down box, select SQL Server


Authentication.

4 In the Login name box, type sa.

© 2014 MicroStrategy Inc. Exercises 165


4 Exercises MicroStrategy Freeform SQL Essentials

5 In the Password box, type Training.

6 Click Connect.

7 If the Object Explorer is not displayed, on the View menu, select Object
Explorer.

8 In Object Explorer, expand Databases, and select the FFSQL_CUST_WH


database.

9 Right-click on the FFSQL_CUST_WH database, and select New Query.

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.

166 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

12 In Microsoft SQL Server Management Studio Express, on the toolbar,


click the Execute icon:

 After you execute the query, you should see a message pane display
below the SQL pane that indicates that the command completed
successfully.

Validate creation of the stored procedure

13 In the Object Explorer, expand the FFSQL_CUST_WH database.

14 Under the FFSQL_CUST_WH database, expand the Programmability


folder, then expand the Stored Procedures subfolder.

15 Ensure that dbo.spPROD_CONTR displays in the list of procedures.

 It displays as the last procedure in the list.


16 On the File menu, select Exit to close Microsoft SQL Server Management
Studio Express.

 When you close Microsoft SQL Server Management Studio


Express, a message window displays asking if you want to save the
SQL. You do not need to save the SQL, so you can click No.

Open the Freeform SQL Editor

17 In MicroStrategy Developer, in the Freeform SQL Exercises folder,


right-click an empty area in the Object Viewer, point to New, and select
Report.

18 In the New Grid window, click the Freeform Sources tab.

19 In the Source list, select Customer Analysis FFSQL.

20 With the Create Freeform SQL report radio button selected, click OK.

Enter the SQL statement

21 In the SQL Statement pane, type Execute spPROD_CONTR.

Map the columns

22 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

© 2014 MicroStrategy Inc. Exercises 167


4 Exercises MicroStrategy Freeform SQL Essentials

23 In the Mapping pane, for Column 1, in the Object box, type Product
Group as the attribute name.

24 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

25 In the Mapping pane, for Column 2, in the Object box, type Product
Group as the attribute name.

26 In the Form drop-down box, select DESC.

27 In the Object Browser, in the Freeform Objects folder, expand the


Product attribute.

 You should have the Product attribute created as part of the


Exercises for Lesson 2 - Creating Freeform SQL Reports.

28 Under the Product attribute, double-click the ID form.

29 Double-click the DESC form.

30 Collapse the Product attribute.

31 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

32 In the Mapping pane, for Column 5, in the Object box, type Product
Revenue as the metric name.

33 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

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.

35 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

168 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

36 In the Mapping pane, for Column 7, in the Object box, type Percent
Contribution of Product to All Revenue as the metric name.

The completed column mapping should look like the following:

Save the Freeform SQL definition

37 Click OK.

Format the metrics

38 In the Report Editor, in Design View, right-click the Product Revenue


metric, point to Formatting, and select Product Revenue Values.

39 In the Format Cells window, on the Number tab, under Category, select
Currency.

40 Click OK.

41 In the Report Editor, in Design View, right-click the Percent


Contribution of Product to Product Group Revenue metric, point to
Formatting, and select Percent Contribution of Product to Product
Group Revenue Values.

42 In the Format Cells window, on the Number tab, under Category, select
Percent.

43 Click OK.

44 In the Report Editor, in Design View, right-click the Percent


Contribution of Product to All Revenue metric, point to Formatting,
and select Percent Contribution of Product to All Revenue Values.

45 In the Format Cells window, on the Number tab, under Category, select
Percent.

46 Under Settings, in the Decimal places box, type 4.

© 2014 MicroStrategy Inc. Exercises 169


4 Exercises MicroStrategy Freeform SQL Essentials

47 Click OK.

Save and run the report

48 Save the report in the Freeform SQL Exercises folder as Product Sales
Analysis.

49 Run the report.

50 Compare your results to the expected report in the Overview section at the
beginning of this exercise.

51 Close the report.

Exercise 4.3: Using a Microsoft Excel File for a Freeform SQL


Report

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.

 Iffile,youyoudocannotuseknowthehow to import external data into a Microsoft Excel


detailed instructions for help.

Create a DSN that connects to the Employee_Survey.xls file and name it


EMP_SURVEY. Create a database instance that points to this DSN and name
it Employee Survey Tables. 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 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.

170 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

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:

 There is no survey data for the Pre-Sales department. Therefore, the


report returns only 11 rows even though there are 12 employee
departments.

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.

You can use the detailed instructions if you want help.

Detailed Instructions

Prepare the Microsoft Excel file

1 Open a blank Microsoft Excel file.

 The instructions in this exercise are for Microsoft Excel 2010.


2 In Microsoft Excel, ensure that the cursor is positioned on the A1 cell in
the worksheet.

3 On the Data tab, click From Other Sources and select From SQL
Server.

© 2014 MicroStrategy Inc. Exercises 171


4 Exercises MicroStrategy Freeform SQL Essentials

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.

6 In the User Name box, type sa.

7 In the Password box, type Training.

8 Click Next.

9 In the Select Database and Table window, in the drop-down box, select
the FFSQL_EMP_WH database.

10 Select the Connect to a specific table check box if it is not already


selected.

11 Select the F_SURVEY table.

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.

16 In the Password box, type Training.

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.

172 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

19 Hold the Shift key and select the F390 cell.

 This action selects all of the imported data.


20 Right-click the selected area, point to Table, and select Convert to
Range.

21 In the warning window, click OK.

22 With the data still selected, right-click, and select Define Name.

23 In the New Name window, in the Name box, type F_SURVEY.

24 Click OK.

25 In the Microsoft Excel worksheet, select the H1 cell.

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.

29 In the User Name box, type sa.

30 In the Password box, type Training.

31 Click Next.

32 In the drop-down box, select the FFSQL_EMP_WH database.

33 Select the Connect to a specific table check box, if it is not already


selected.

34 Select the L_EMP_DPTM table.

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.

© 2014 MicroStrategy Inc. Exercises 173


4 Exercises MicroStrategy Freeform SQL Essentials

39 In the Password box, type Training.

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.

42 Hold the Shift key and select the J13 cell.

 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.

44 In the warning window, click OK.

45 With the data still selected, right-click, and select Define Name.

46 In the New Name window, in the Name box, type L_EMP_DPTM.

47 Click OK.

48 On the File menu, select Save.

49 Name the file Employee_Survey.xls.

50 In the Safe As type drop-down list, select Excel 97-2003 Workbook.

51 In the Microsoft Office Excel Compatibility Checker warning, click


Continue.

52 Close the file.

Create a DSN to connect to the file

1 On the Start menu, select All Programs, select MicroStrategy Tools, and
select Connectivity Wizard.

 If the User Account Control window displays, click Yes.


2 In the MicroStrategy Connectivity Wizard welcome window, click Next.

3 In the Driver Selection window, select Other Relational Databases.

4 Click Next.

174 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

5 In the Driver Selection window, select Microsoft Excel Driver(*.xls).

6 Click Next.

7 In the ODBC Microsoft Excel Setup window, in the Data Source Name
box, type EMP_SURVEY as the DSN name.

8 Click Select Workbook.

9 In the Select Workbook window, browse to the C:\MSTR\FFSQL folder


and select the Employee_Survey.xls file.

10 Click OK.

11 In the ODBC Microsoft Excel Setup window, click OK.

12 In the DSN Created window, click OK.

Create a database instance to point to the DSN

13 In MicroStrategy Developer, under the MicroStrategy Analytics Modules


project source, expand Administration.

14 Expand Configuration Managers.

15 Right-click Database Instances, point to New, and select Database


Instance.

16 In the Database Instances window, on the General tab, in the Database


instance name box, type Employee Survey Tables as the database
instance name.

17 In the Database connection type drop-down box, select Microsoft Excel


2000/2003.

18 Click New.

19 In the Database Connections window, on the General tab, in the Database


connection name box, type Employee Survey Tables as the database
connection name.

20 Under Local system ODBC data sources, select EMP_SURVEY.

21 Under Default database login name, select Excel.

© 2014 MicroStrategy Inc. Exercises 175


4 Exercises MicroStrategy Freeform SQL Essentials

 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.

23 In the Database Instances window, under Database connection (default),


select Employee Survey Tables.

24 Click OK.

Configure the database instance for Freeform SQL reporting

25 In the MicroStrategy Analytics Modules project source, right-click the


MicroStrategy Tutorial project and select Project Configuration.

26 In the Project Configuration window, in the Categories list, expand the


Database instances category.

27 In the SQL Data warehouses subcategory, under Available Data Mart,


Query Builder, Freeform and non-primary warehouse database instances,
select Employee Survey Tables.

28 In the message window, click No.

29 In the Project Configuration window, click OK.

Open the Freeform SQL Editor

30 In the Freeform SQL Exercises folder, right-click an empty area in the


Object Viewer, point to New, and select Report.

31 In the New Grid window, click the Freeform Sources tab.

32 In the Source list, select Employee Survey Tables.

33 With the Create Freeform SQL report radio button selected, click OK.

176 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

Enter the SQL statement

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:

Map the columns

35 In the Freeform SQL Editor, in the Object Browser, in the Freeform


Objects folder, double-click <Add New Attribute Form>.

36 In the Mapping pane, for Column 1, in the Object box, type Employee
Department as the attribute name.

37 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

38 In the Mapping pane, for Column 2, in the Object box, type Employee
Department as the attribute name.

39 In the Form drop-down box, select DESC.

40 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

41 In the Mapping pane, for Column 3, in the Object box, type Average
Satisfaction Score as the metric name.

The completed column mapping should look like the following:

42 Click OK.

© 2014 MicroStrategy Inc. Exercises 177


4 Exercises MicroStrategy Freeform SQL Essentials

Format the metric

43 In the Report Editor, in Design View, right-click the Average


Satisfaction Score metric, point to Formatting, and select Average
Satisfaction Score Values.

44 In the Format Cells window, on the Number tab, under Category, select
Fixed.

45 Under Settings, in the Decimal places box, type 1.

46 Click OK.

Save and run the report

47 Save the report in the Freeform SQL Exercises folder as 2011 Employee
Survey Analysis.

48 Run the report.

49 Compare your results to the expected report in the Overview section at the
beginning of this exercise.

50 Close the report.

Exercise 4.4: Using Text Files for a Freeform SQL Report

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.

178 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

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:

You can use the detailed instructions if you want help.

Detailed Instructions

Create a DSN to connect to the files

1 On the Start menu, in the Search programs and files box, type
odbcad32.exe and press Enter.

© 2014 MicroStrategy Inc. Exercises 179


4 Exercises MicroStrategy Freeform SQL Essentials

2 Under Programs, select odbcad32.exe

3 In the ODBC Data Source Administrator window, on the System DSN tab,
click Add.

4 In the Create New Data Source window, select Microstrategy ODBC


Driver for Text.

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.

Define the columns for the Division.txt file

8 Click the Advanced tab.

9 On the Advanced tab, click Define.

10 In the Define File window, browse to the C:\MSTR\FFSQL folder and


select the Division.txt file.

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.

15 Under Column Information, click Guess.

16 Verify that all the columns in the file are displayed and that the correct
data type is displayed for each column.

 The columns should include DIVISION_ID and


DIVISION_NAME. DIVISION_ID should be set to a numeric data
type, and DIVISION_NAME should be set to a varchar data type.
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.

180 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

17 Click OK.

Define the columns for the Manager.txt file

18 In the Define File window, select the Manager.txt file.

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.

 Comma is the default delimiter for the Table Type box.


23 Under Column Information, click Guess.

24 Verify that all the columns in the file are displayed and that the correct
data type is displayed for each column.

 The columns should include MANAGER_ID, MANAGER_NAME,


and DIVISION_ID. MANAGER_ID and DIVISION_ID should be
set to a numeric data type, and MANAGER_NAME should be set
to a varchar data type. 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.

25 Click OK.

Define the columns for the Employee.txt file

26 In the Define File window, select the Employee.txt file.

27 Click Open.

28 In the Define Table window, under Table Information, in the Table box,
type LU_EMPLOYEE.

29 Select the Column Names in First Line check box.

© 2014 MicroStrategy Inc. Exercises 181


4 Exercises MicroStrategy Freeform SQL Essentials

30 In the Table Type drop-down box, ensure that Comma is selected as the
delimiter.

 Comma is the default delimiter for the Table Type box.


31 Under Column Information, click Guess.

32 Verify that all the columns in the file are displayed and that the correct
data type is displayed for each column.

 The columns should include EMPLOYEE_ID,


EMPLOYEE_NAME, and MANAGER_ID. EMPLOYEE_ID and
MANAGER_ID should be set to a numeric data type, and
EMPLOYEE_NAME should be set to a varchar data type. 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.

33 Click OK.

34 In the Define File window, click Cancel.

35 In the ODBC Text Driver Setup window, click OK.

36 In the ODBC Data Source Administrator window, click OK.

Create a database instance to point to the DSN

37 In the MicroStrategy Analytics Modules project source, expand the


Administration icon.

38 Expand the Configuration Managers icon.

39 Right-click Database Instances, point to New, and select Database


Instance.

40 In the Database Instances window, on the General tab, in the Database


instance name box, type Employee Organization Text Files.

41 In the Database connection type drop-down box, select Generic DBMS.

42 Click New.

43 In the Database Connections window, on the General tab, in the Database


connection name box, type Employee Organization Text Files as the
database connection name.

182 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

44 Under Local system ODBC data sources, select EMP_ORG_INFO.

45 Under Default database login name, select Text.

 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.

47 In the Database Instances window, under Database connection (default),


select Employee Organization Text Files.

48 Click OK.

Configure the database instance for Freeform SQL reporting

49 In the MicroStrategy Analytics Modules project source, right-click the


MicroStrategy Tutorial project and select Project Configuration.

50 In the Project Configuration window, in the Categories list, expand the


Database instances category.

51 In the SQL Data warehouses subcategory, under Available Data Mart,


Query Builder, and Freeform database instances, select Employee
Organization Text Files.

52 In the message window, click No.

53 In the Project Configuration window, click OK.

Open the Freeform SQL Editor

54 In the Freeform SQL Exercises folder, right-click an empty area in the


Object Viewer, point to New, and select Report.

55 In the New Grid window, click the Freeform Sources tab.

56 In the Source list, select Employee Organization Text Files.

57 With the Create Freeform SQL report radio button selected, click OK.

© 2014 MicroStrategy Inc. Exercises 183


4 Exercises MicroStrategy Freeform SQL Essentials

Enter the SQL statement

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:

59 Close the Exercises SQL Microsoft Word document.

Map the columns

60 In the Freeform SQL Editor, in the Object Browser, in the Freeform


Objects folder, double-click <Add New Attribute Form>.

61 In the Mapping pane, for Column 1, in the Object box, type Division as
the attribute name.

62 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

63 In the Mapping pane, for Column 2, in the Object box, type Division as
the attribute name.

64 In the Form drop-down box, select DESC.

65 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

66 In the Mapping pane, for Column 3, in the Object box, type Manager
FFSQL as the attribute name.

67 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Attribute Form>.

68 In the Mapping pane, for Column 4, in the Object box, type Manager
FFSQL as the attribute name.

69 In the Form drop-down box, select DESC.

184 Exercises © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Exercises 4

70 In the Object Browser, in the Freeform Objects folder, double-click <Add


New Metric>.

71 In the Mapping pane, for Column 5, in the Object box, type Number of
Employees as the metric name.

The completed column mapping should look like the following:

Save the Freeform SQL definition

72 Click OK.

Add subtotals

73 In the Report Editor, in Design View, on the Data menu, select Subtotals.

74 In the Subtotals window, on the Definition tab, under Available subtotals,


select the Total check box.

75 Click OK.

Save and run the report

76 Save the report in the Freeform SQL Exercises folder as Employee


Organization Analysis.

77 Run the report.

78 Compare your results to the expected report in the Overview section at the
beginning of this exercise.

79 Close the report.

© 2014 MicroStrategy Inc. Exercises 185


4 Exercises MicroStrategy Freeform SQL Essentials

186 Exercises © 2014 MicroStrategy Inc.


5
SECURITY FOR FREEFORM
SQL REPORTS

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.

© 2014 MicroStrategy Inc. 187


5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Lesson Objectives

After completing this lesson, you will be able to:


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.

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)

• Use security filters in Freeform SQL reports. (Page 197)

188 Lesson Objectives © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5

Configuring Access to Freeform SQL Objects

After completing this topic, 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.

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.

To view the access control list for an object:

1 Right-click the object and select Properties.

2 In the Properties window, under the Categories list, select Security.

3 View the access control list for the object.

© 2014 MicroStrategy Inc. Configuring Access to Freeform SQL Objects 189


5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

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

• Full Control—Enables the user or group to browse, read, write, delete,


control, use, and execute the object (grants all permissions)

• Denied All—Prevents any level of access to the object for the user or
group (denies all permissions)

190 Configuring Access to Freeform SQL Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5

• Default—Enables the same level of access to the object as the user or


group has for the parent folder in which the object resides

• Custom—Enables you to configure a custom level of access for the user or


group by granting and denying object 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.

Access Control List for Objects in Freeform SQL Reports


You can map columns in Freeform SQL reports to existing project attributes
or to Freeform SQL objects (attributes and metrics that you create
specifically for Freeform SQL reports). If you map a column to an existing
project attribute, as with standard reports, the access control list of that
attribute determines the permissions.

However, Freeform SQL objects work a little differently. They inherit a


default access control list that is defined at the project level. By default, this
access control list contains the following permissions:
Default Access Control List for Freeform SQL Objects

User/Group Level of Access

Administrator Full Control

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.

 Inuseraddition to the permissions in the default access control list, the


who creates a Freeform SQL object also has Full Control access
for the object.

© 2014 MicroStrategy Inc. Configuring Access to Freeform SQL Objects 191


5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

To view the access control list of a Freeform SQL object:

1 Open a Freeform SQL report in Design View.

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.

3 In the Freeform SQL Editor, in the Object Browser, in the Freeform


Objects folder, right-click the object and select Properties.

4 In the Properties window, under the Properties category, select Security.

5 View the access control list for the object.

 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.

192 Configuring Access to Freeform SQL Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5

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.

Modifying the Default Access Control List for Freeform SQL


Objects
You can change the default access control list that is applied to new Freeform
SQL objects by modifying the related project configuration setting.

To modify the default access control list for new Freeform SQL objects:

1 In MicroStrategy Developer, under the appropriate project source,


right-click the project for which you want to modify the access control list,
and select Project Configuration.

© 2014 MicroStrategy Inc. Configuring Access to Freeform SQL Objects 193


5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

2 In the Project Configuration window, under the Project definition


category, select Security.

3 Under Access control, besides Set Freeform SQL and MDX objects default
security, click Modify.

4 In the Properties window, modify the access control list as desired.

5 Click OK.

6 In the Project Configuration window, 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

194 Configuring Access to Freeform SQL Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5

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.

For example, if you now create an Employee Gender attribute (a new


Freeform SQL object) as part of a Freeform SQL report, its access control list
looks like the following:

© 2014 MicroStrategy Inc. Configuring Access to Freeform SQL Objects 195


5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Access Control List for the Employee Gender Attribute

Notice that the access control list for the Employee Gender attribute includes
the Developers user group, granting them Modify access.

196 Configuring Access to Freeform SQL Objects © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Security for Freeform SQL Reports 5

Using Security Filters in Freeform SQL Reports

After completing this topic, you will be able to:


Use security filters in Freeform SQL reports.

One of the application-level security features available in MicroStrategy is


security filters. A security filter is a filter that you can assign to a user or
group to limit the result set that the user or group obtains when executing a
report or browsing attribute elements. Security filters enable you to control at
the MicroStrategy level the warehouse data that is available to specific users
or groups.

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.

For example, consider the following report:


Report Without Security Filter

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.

A security filter has three components that you can define:

• 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

• Bottom Range Attribute—The lowest level of detail that the security


filter allows a user or group to view

In the MicroStrategy Tutorial project, in the Geography hierarchy, the


Country attribute is higher than the Region attribute. However, if you want to
force users to only be able to see as high as the Region attribute, you can set
Region as the Top Range Attribute to prevent users from accessing data
stored at a higher level than Region.

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

Applying Security Filters to Freeform SQL Reports


When a user executes a Freeform SQL report, by default, any security filter
assigned either to that user, or a group to which the user belongs, is not
intersected with the report filter conditions. However, you can apply security
filters to a Freeform SQL report by inserting a security filter placeholder into
the SQL statement for the report. Because the SQL statement for a Freeform
SQL report is statically defined rather than dynamically generated by the SQL
Engine, you need to manually embed the security filter string in the report
SQL. When a user with a security filter executes the Freeform SQL report, the
placeholder is replaced with that user’s security filter.

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

Security Filter Parameters

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:

• Replacement String—Defines the placeholder that is inserted into the


SQL statement, which is replaced by the security filter when a user runs
the report

• Attribute Mappings—Defines the columns that replace attribute forms


contained in security filters when building the security filter expression
for the report

• Ignored Attributes—Identifies any attribute forms contained in security


filters that you want to ignore when building the security filter expression
for the report

• 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.

How you configure each of these parameters determines the behavior of


security filters within the Freeform SQL report.

Inserting 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

To insert a security filter placeholder in a Freeform SQL report:

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.

2 On the Edit menu, select Insert Security Filter.

3 In the Freeform SQL Security Filter Dialog window, in the Replacement


String box, do one of the following:

If the security filter placeholder is the only information in the WHERE


clause, type Where Security Filter.

OR

If the security filter placeholder is combined with other conditions or


joins in the WHERE clause, type and Security Filter.

 You cannot type “where” or “and” directly in the SQL Statement


pane. Entering this syntax as part of the replacement string
ensures that all the syntax related to the security filter is removed
from the report SQL if a user without a security filter runs the
report. If you type this syntax directly in the report SQL, “where”
and “and” are not part of the replacement string. Therefore, if a
user without a security filter runs the report, the incomplete
security filter expression produces invalid SQL, which causes the
report to fail.

4 If you want to include an attribute in the security filter expression that is


generated for the report, in the Object Browser, browse to the desired
attribute.

 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.

 The string should use the following format: <table or alias


name>.<column name> (for example, “a.REGION_ID” where “a”
is the alias used for the LU_REGION table in the SQL statement
for the report). If you use table aliases in the SQL statement, you
must use those aliases, not the table names in the string.

8 Repeat steps 4 to 7 for each attribute that you want to include in the
security filter expression for the report.

9 If you want to ignore an attribute in the security filter expression that is


generated for the report, in the Object Browser, browse to the desired
attribute.

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.

 This option is applicable only if your environment contains


security filters that include top and bottom range attributes. If you
have security filters that contain top and bottom range attributes,
you must select this option. Otherwise, the report will fail when
users who are associated with those security filters execute it.

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.

 You can edit the definition of a security filter placeholder by


right-clicking the placeholder and selecting Edit.

© 2014 MicroStrategy Inc. Using Security Filters in Freeform SQL Reports 203
5 Security for Freeform SQL Reports MicroStrategy Freeform SQL Essentials

Interaction Between Freeform SQL Reports and Security


Filters

Based on whether you configure a security filter placeholder for a Freeform


SQL report and how you define it, a Freeform SQL report can interact with
security filters in different ways. The following table describes the behavior of
Freeform SQL reports for various security filter configurations:
Security Filters and Freeform SQL Reports

Security Filter
Freeform SQL Report Behavior
Configuration

No security filter The report executes without applying any


placeholder exists security filters used in the project.

A security filter The report applies security filter


placeholder exists qualifications for attributes that are mapped
in the placeholder definition.

The report does not apply security filter


qualifications for attributes that are ignored
in the placeholder definition.

The report fails for any users with security


filters that contain attributes that are left out
of the placeholder definition (not mapped or
ignored).

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 Filters with Top and Bottom Range Attributes

Security Filter
Freeform SQL Report Behavior
Configuration

A security filter The report executes as long as the level of


placeholder exists and the report is not at a higher or lower level
the option to evaluate the than the user is allowed to view.
report level is configured

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

Security Filters and Freeform SQL Example

To illustrate how security filters are applied to Freeform SQL reports,


consider the following example. You have three users- User A, User B, and
User C- who are all going to be executing the same Freeform SQL report.
User A has a security filter that looks like the following:
Security Filter for User A

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 has a security filter that looks like the following:


Security Filter for User B

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 has a security filter that looks like the following:


Security Filter for User C

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:

• When you map a column to an existing project attribute, the access


control list of that attribute determines the permissions.

• Freeform SQL objects inherit the default access control list defined at the
project level.

• When a user executes a Freeform SQL report, by default, any security


filter assigned either to that user, or a group to which the user belongs, is
not intersected with the report filter conditions.

• You can apply security filters to a Freeform SQL report by inserting a


security filter placeholder into the SQL statement for the report. When a
user with a security filter executes the Freeform SQL report, the
placeholder is replaced with that user’s security filter.

214 Lesson Summary © 2014 MicroStrategy Inc.


A
CUSTOMER ANALYSIS
SCHEMA

Appendix Description

This appendix contains the physical schema for the FFSQL_CUST_WH


database that is used throughout the course lessons and exercises. You may
need to reference this information as you complete the exercises in the course.

© 2014 MicroStrategy Inc. 215


A Customer Analysis Schema MicroStrategy Freeform SQL Essentials

Customer Analysis Schema


The following schema shows the tables in the FFSQL_CUST_WH database.

Customer Schema

216 Customer Analysis Schema © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Customer Analysis Schema A

Product Schema

Time Schema

© 2014 MicroStrategy Inc. Customer Analysis Schema 217


A Customer Analysis Schema MicroStrategy Freeform SQL Essentials

Transaction Schema

Fact Tables Schema

218 Customer Analysis Schema © 2014 MicroStrategy Inc.


B
EMPLOYEE ANALYSIS SCHEMA

Appendix Description

This appendix contains the physical schema for the FFSQL_EMP_WH


database that is used throughout the course lessons and exercises. You may
need to reference this information as you complete the exercises in the course.

© 2014 MicroStrategy Inc. 219


B Employee Analysis Schema MicroStrategy Freeform SQL Essentials

Employee Analysis Schema


The following schema shows the tables in the FFSQL_EMP_WH database.

Benefits Schema

Compensation Schema

220 Employee Analysis Schema © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Employee Analysis Schema B

Contractor Schema

Employee Schema

© 2014 MicroStrategy Inc. Employee Analysis Schema 221


B Employee Analysis Schema MicroStrategy Freeform SQL Essentials

Employee Status Schema

Jobs Schema

Qualification Schema

222 Employee Analysis Schema © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Employee Analysis Schema B

Survey Schema

Time Schema

© 2014 MicroStrategy Inc. Employee Analysis Schema 223


B Employee Analysis Schema MicroStrategy Freeform SQL Essentials

Time Off Schema

Fact Tables Schema

224 Employee Analysis Schema © 2014 MicroStrategy Inc.


INDEX

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

© 2014 MicroStrategy Inc. 225


Index MicroStrategy Freeform SQL Essentials

Freeform SQL report creation 131 Freeform SQL objects


overview 129 access control list 189
support 130 default access control list 191
displaying managed objects 59 modifying default access control
documents list 193
Freeform SQL reports 74 Freeform SQL report creation 43
drilling configuring database instances for Mi-
crosoft Excel files 143
Freeform SQL reports 28, 68
configuring database instances for text
DSNs
files 152
Microsoft Excel files 142
creating DSNs for Microsoft Excel
DSNs, text files 149 files 142
defining the SQL statement 44
E derived table expressions 131
editing managed objects 60 mapping columns 46
element list prompts 99 Microsoft Excel files 139, 146
Freeform SQL reports 103 overview 35
Excel files preparing Microsoft Excel files 140
configuring database instances 143 preparing text files 148
creating DSNs 142 prompts 100
creating tables 140 selecting the database instance 43
Freeform SQL report creation 139, stored procedures 136
146 text files 147
Freeform SQL report creation, creating
DSNs for text files 149
F Freeform SQL report creation, text
filters files 155
Freeform SQL reports 65 Freeform SQL reports 21
Freeform SQL adding new prompts 101
benefits 23 common table expressions 129
overview 21 configuring database instances 36
Freeform SQL and security filters derived table expressions 129
example 205 drilling 28, 68
Freeform SQL and standard reports element list prompts 103
comparison 24 filters 65
Freeform SQL Editor 39 inserting existing prompts 102
accessing for existing Freeform SQL inserting security filter
reports 41 placeholders 201
components 41 non-relational data sources 139

226 © 2014 MicroStrategy Inc.


MicroStrategy Freeform SQL Essentials Index

optional prompts 111 146


prompt options 100 modifying default access control list
prompt usage 99 Freeform SQL objects 193
prompt-dependent SQL 111 multipass SQL
Report Data Options 28 common table expressions 129
report formatting and data derived table expressions 129
manipulations 25 multipass SQL, stored procedures 135
Report Services documents 74
saving 51
security filter interaction 204
N
security filter parameters 200 non-relational data sources
security filters 197 Freeform SQL reports 139
shortcut metrics 27
structure 21 O
supported administrative functions 29
optional prompts
supported reporting functions 25
Freeform SQL reports 111
supported SQL 45 overview
value prompts 107
course 30
VLDB properties 28
Freeform SQL reports, stored
procedures 135 P
prompt options
I Freeform SQL reports 100
prompt usage
inserting existing prompts
Freeform SQL reports 99
Freeform SQL reports 102
prompt-dependent SQL
Freeform SQL reports 111
M prompts 99
managed objects 55 Freeform SQL report creation 100
deleting 63 prompts, element list 99
editing 60 prompts, value 99
properties 56 properties
search options 59 managed objects 56
viewing 57
mapping columns R
Freeform SQL report creation 46
Report Data Options
Microsoft Excel files
Freeform SQL reports 28
Freeform SQL report creation 139,
report formatting

© 2014 MicroStrategy Inc. 227


Index MicroStrategy Freeform SQL Essentials

Freeform SQL reports 25 support


Report Services documents derived and common table
Freeform SQL reports 74 expressions 130
reporting functions supported administrative functions
Freeform SQL reports 25 Freeform SQL reports 29
report-level VLDB properties supported SQL
Freeform SQL reports 28 Freeform SQL reports 45

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

228 © 2014 MicroStrategy Inc.

Potrebbero piacerti anche