SlideShare a Scribd company logo
S I T U A T I O N A L E X A M P L E S A N D P R O P E R
S Y N T A X F O R V A R I O U S C A S E S
B R Y A N L . M A C K
Cognos Macros
Why Do We Need Macros?
In Cognos, we dynamically filter data based on prompt
values input by the user.
When using Custom SQL for a report’s source, Cognos
provides filters for us to filter data.
But what exactly is it filtering?
Why Do We Need Macros?
Refer to the following 2 SQL scripts in SQL Developer:
 Query 1:
 Query 2:
The only difference in Query2 is the academic_period filter in the nested query; Query2
correctly filters our result set, as our desired output count is 2524.
Why Do We Need Macros?
Our first SQL Script is embedded to Cognos as a
Query, minus the academic period filter:
Then a filter is added to the query via Cognos
Why Do We Need Macros?
If we use term 201320, and export our result set to
Excel, we can see that we have 12148 results (the top 2
rows in Excel are header rows)
As we mentioned earlier, this is not our desired output.
Why Do We Need Macros?
Here is the SQL Cognos has generated:
The academic_period filter is being placed incorrectly within the query.
Why Do We Need Macros?
Let’s revisit slide 3’s results:
Query 1:
Query 2:
Shouldn’t we be limiting this to 2524 results? Cognos is not applying the
filter to the nested query
What is a Cognos Macro?
A Cognos macro allows you to place user-selected
prompt values wherever you’d like within custom SQL.
The macro allows you to manipulate the prompt values
where necessary, and use them for more precise
filtering and processing.
In our example, we want the filter to be placed in the
nested query rather than the outmost query.
Proof of Concept
We can filter the prompt values wherever we desire, in this case, within
the nested query:
We can see we now return 2524 rows
The macro worked and our results are correctly filtered. You can see the
macro in the SQL – but how does it work?
Macro Syntax
#prompt(ParameterName,Datatype,Defaultvalue,PreText,Sou
rce,PostText)#
ParameterName: Mandatory. This is what you named your prompt value’s parameter.
Datatype: Optional. The default value is ‘string’. Prompt values are validated. In the case of strings, the
provided value is enclosed in single quotation marks and embedded single quotation marks are doubled.
Defaultvalue: Optional. Value if the user makes no selection from an optional prompt
Pretext: Optional. Text to use before displaying the option the user inputs with the prompt.
Example: This is the open-parentheses when using #promptmany for an IN statement (we’ll get
to that in a bit)
Source: Optional. The value(s) selected in the prompt
Posttext: Optional. Text to use after displaying the option the user inputs with the prompt.
Example: This is the close-parentheses when using #promptmany for an IN statement
Ways I’ll Demonstrate Macros
Using Oracle join syntax, I will demonstrate all of the
following macro scenarios.
 Inner Join (Mandatory Prompts, Optional Prompts)
 Outer Join (Mandatory Prompts, Optional Prompts)
 Conditional Inner/Outer
 If optional prompt used – use inner join
 If optional prompt ignored – use outer join
 Date/Date Range (Mandatory Prompts, Optional Prompts)
 For use within a function
 Equal Operator (=) vs IN statement
 LIKE clause
 HAVING clause
Ways I Will NOT Demonstrate Macros
Many!
There are countless combinations of inner join, outer join,
mandatory/optional prompts, single/multi select,
characters/numbers/dates, etc. etc. etc.
I can’t possibly demonstrate every way to do this, so I will
try to build up your base knowledge so you can figure out
scenarios I have not demonstrated.
I will also not be using ANSI join syntax, I will be using
Oracle join syntax
Inner-Join Mandatory Macro
Compare characters (=)
<field> = #prompt('parm_multi_source')#
Compare characters (in)
<field> IN (#promptmany('parm_carrier')#)
Real example from a Cognos report:
Inner-Join Optional Macro
Compare Characters (=)
<field> =
(#prompt('parm_carrier','string',’<field>’)#)
Let’s say the field is “myfield” and the user selects the prompt value “I Hate
Cognos”. The generated SQL will be:
myfield = ‘I Hate Cognos’
If the user does not use the optional prompt, the macro will generate the following
SQL:
myfield = myfield
Note: You can convert to “IN” by changing the equal to the word IN, and change “prompt” to
“promptmany”
Inner-Join Optional Macro Examples
Outer-Join Mandatory Macro
Follow the same logic as Inner-Join Mandatory, just
add the plus sign for Oracle’s outer-join logic
and s.spriden_id(+) = (#prompt(‘myparam')#)
and s.spriden_id(+) IN (#promptmany(‘myparam’)#)
Outer-Join Mandatory Macro Example
Outer-Join Optional Macro
Compare Characters (=)
This will build out the entire AND statement for you
#prompt('parmYEAR','string','and 1=1','and pdrhioc_year(+) = ')#
Read this as: parmYear is my string parameter used in my prompt, when the user doesn’t use the prompt, insert
the text “and 1=1”, when the user uses the prompt insert “and pdrhioc_year(+) = “ followed by the value they
input.
Compare Characters (IN)
Option 1: build out the entire AND statement
#promptmany('parmYEAR','string','and 1=1','and pdrhioc_year(+) IN (','',')')#
The last 3 parameters are: (1) what to insert before the prompt value (2) The prompt value itself (3) what to insert
after the prompt value
Option 2: This requires the macro to be within an AND statement
and (a.account_entity_ind IN (#promptmany('ParameterEnt','string',sq('NotSelected'))#)
OR
('NotSelected') in (#promptmany('ParameterEnt','string',sq('NotSelected'))#)
)
The first part of the OR statement addresses the outer-join, the second part of the OR statement keeps the join in
tact when the optional prompt is not used.
Outer-Join Optional Macro Examples
Conditional Outer/Inner Join Macro
Requirements:
 Have an optional prompt
 If optional prompt selected, use inner join
 If optional prompted ignored, use outer join
and ad.account_uid = sar.person_uid
#prompt('ParameterStuAttr', 'string', '(+)', '/*', '', '*/'
)#
Conditional Outer/Inner Join Macro
 and ad.account_uid = sar.person_uid #prompt(
 'ParameterStuAttr', --parameter name
 'string', --DataType
 '(+)', --Default text (when prompt ignored)
 '/*', --text to precede the prompt text when used
 '', --inputs the value selected in the prompt
 '*/' --text to follow the value in prompt when used
 )#
When the prompt is used, the macro puts /* comments around the prompt value it is
inserting*/, so the code processes nothing and leaves the join (account_uid =
person_uid) as inner.
When the prompt is NOT used, the macro places (+) after the hard-coded join, thus
creating an outer join
Reminder: I am using Oracle outer-join syntax
Conditional Outer/Inner Join Macro Example
Date Prompts
Mandatory Inner:
Option 1: when using ISO 8601 date format
<field> = to_timestamp(#prompt(‘parm_date')#,'YYYY-
MM-DD"T"HH24:MI:SS.ff3')
Option 2: when using other date format standards
<field> = to_date(#prompt('parm_date')#,'yyyy-mm-dd')
Date Prompt Examples
Date Range
After exhaustive searching and testing, I have been
unable to find a way to extract the date range values
from a date range prompt with a macro, so you need to
create two individual date prompts (date_from and
date_to)….
Date Range Optional Prompt Example
(
(trunc(ad.entry_date) >=
trunc(to_date(#prompt('ParameterEntryFrom','string',sq('NotSelected'))#,'YYYY-MM-DD'))
OR
('NotSelected') = #prompt('ParameterEntryFrom','string',sq('NotSelected'))#
)
and
(trunc(ad.entry_date) <=
trunc(to_date(#prompt('ParameterEntryTo','string',sq('NotSelected'))#,'YYYY-MM-DD'))
OR
('NotSelected') = #prompt('ParameterEntryTo','string',sq('NotSelected'))#
)
)
This syntax uses an OR statement for each of the two parameters. The first
half of each OR block is for if the optional prompt is used, the second half is
for if the prompt is not used.
Note: I typed the code instead of screen shot here so I could color-code the parentheses and make the code
more readable for the example.
Date Range Mandatory Prompt Example
LIKE clause
To use a LIKE clause with optional, multi-select
prompt:
and eec.earn_code IN (select m.allowance from
mappings m where m.deductions like
('%'||#promptmany('parm_carrier','string','bd.carrier'
)#||'%'))
HAVING clause
Sometimes we need to filter on the aggregates, which
is used in SQL with the HAVING clause. Suppose we
have a prompt filtering on an aggregate amount that a
user types into a text prompt – how would we write
this in a macro? Add a caveat: this is an optional
prompt
having sum(ad.balance) >=
(#prompt('ParameterBalance','string','sum(ad.balance
)')#)
Having Clause Example
Function on top of Prompt Value
Sometimes we will get a prompt value and need to use
it to calculate the proper filter. In this case, we use the
prompt value (parm_s) as a parameter to a function
(odsmgr.f_get_pidm) to return a different value upon
which we will filter. We simply wrap the entire macro
within the function call:
And person_uid in
odsmgr.f_get_pidm(#promptmany('parm_s','string','p
erson_uid')#)
Case Statement/Function using Date Prompt Macro
Note: formatted in SQL developer for readability
Wrapping Up
I hope you find this somewhat helpful.
Even if you aren’t using the Oracle RDBMS, you can
use these syntax examples to create macros that work
for you.
If you have other concrete examples you’d like me to
add to this presentation, feel free to let me know and
I’ll consider adding them here.
Thank You!
Bryan L. Mack
fleetmack@gmail.com

More Related Content

What's hot

Security In LTE Access Network
Security In LTE Access NetworkSecurity In LTE Access Network
Security In LTE Access Network
Sukhvinder Singh Malik
 
Code congestion problem analysis
Code congestion problem analysisCode congestion problem analysis
Code congestion problem analysis
Syed Zahid Shah
 
national contingeny plan for electioneering 2013 with team revion 29th j...
national contingeny plan for electioneering 2013 with team revion 29th j...national contingeny plan for electioneering 2013 with team revion 29th j...
national contingeny plan for electioneering 2013 with team revion 29th j...Amb Steve Mbugua
 
Zte umts load-monitoring and expansion guide
Zte umts load-monitoring and expansion guideZte umts load-monitoring and expansion guide
Zte umts load-monitoring and expansion guide
Alfri Dinata
 
Huawei GSM Principles
Huawei GSM PrinciplesHuawei GSM Principles
Huawei GSM Principles
Achmad Fauzi
 
zte umts-cs-call-drop-analysis-guide-zte
zte umts-cs-call-drop-analysis-guide-ztezte umts-cs-call-drop-analysis-guide-zte
zte umts-cs-call-drop-analysis-guide-zte
3ggprs
 
UMTS/WCDMA Call Flows for PS services
UMTS/WCDMA Call Flows for PS servicesUMTS/WCDMA Call Flows for PS services
UMTS/WCDMA Call Flows for PS services
Justin MA (馬嘉昌)
 
Generic framing protocol
Generic framing protocolGeneric framing protocol
Generic framing protocol
MapYourTech
 
Mobile communication process or cellular network
Mobile communication process or cellular networkMobile communication process or cellular network
Mobile communication process or cellular network
Sudhanshu Jha
 
08102014_Huawei handovers-handover-algo
08102014_Huawei handovers-handover-algo08102014_Huawei handovers-handover-algo
08102014_Huawei handovers-handover-algo
herobinh
 
OFDMA
OFDMAOFDMA
Beginners: UICC & SIM
Beginners: UICC & SIMBeginners: UICC & SIM
Beginners: UICC & SIM
3G4G
 
3 g optimization interview topics
3 g optimization interview topics3 g optimization interview topics
3 g optimization interview topics
Bouziane Beldjilali
 
Gsm rf interview questions
Gsm rf interview questionsGsm rf interview questions
Gsm rf interview questionsradira03
 
Fast dormancy
Fast dormancyFast dormancy
Fast dormancy
Dono Miguel
 
Simplified Call Flow Signaling: 2G/3G Voice Call
Simplified Call Flow Signaling: 2G/3G Voice CallSimplified Call Flow Signaling: 2G/3G Voice Call
Simplified Call Flow Signaling: 2G/3G Voice Call
3G4G
 

What's hot (20)

Security In LTE Access Network
Security In LTE Access NetworkSecurity In LTE Access Network
Security In LTE Access Network
 
Code congestion problem analysis
Code congestion problem analysisCode congestion problem analysis
Code congestion problem analysis
 
national contingeny plan for electioneering 2013 with team revion 29th j...
national contingeny plan for electioneering 2013 with team revion 29th j...national contingeny plan for electioneering 2013 with team revion 29th j...
national contingeny plan for electioneering 2013 with team revion 29th j...
 
Hsdpa principles
Hsdpa principlesHsdpa principles
Hsdpa principles
 
Zte umts load-monitoring and expansion guide
Zte umts load-monitoring and expansion guideZte umts load-monitoring and expansion guide
Zte umts load-monitoring and expansion guide
 
Huawei GSM Principles
Huawei GSM PrinciplesHuawei GSM Principles
Huawei GSM Principles
 
zte umts-cs-call-drop-analysis-guide-zte
zte umts-cs-call-drop-analysis-guide-ztezte umts-cs-call-drop-analysis-guide-zte
zte umts-cs-call-drop-analysis-guide-zte
 
UMTS/WCDMA Call Flows for PS services
UMTS/WCDMA Call Flows for PS servicesUMTS/WCDMA Call Flows for PS services
UMTS/WCDMA Call Flows for PS services
 
Generic framing protocol
Generic framing protocolGeneric framing protocol
Generic framing protocol
 
Mobile communication process or cellular network
Mobile communication process or cellular networkMobile communication process or cellular network
Mobile communication process or cellular network
 
Call flows
Call flowsCall flows
Call flows
 
08102014_Huawei handovers-handover-algo
08102014_Huawei handovers-handover-algo08102014_Huawei handovers-handover-algo
08102014_Huawei handovers-handover-algo
 
OFDMA
OFDMAOFDMA
OFDMA
 
Nemo outdoor-6-0-manual
Nemo outdoor-6-0-manualNemo outdoor-6-0-manual
Nemo outdoor-6-0-manual
 
Beginners: UICC & SIM
Beginners: UICC & SIMBeginners: UICC & SIM
Beginners: UICC & SIM
 
3 g optimization interview topics
3 g optimization interview topics3 g optimization interview topics
3 g optimization interview topics
 
Handover 3g
Handover 3gHandover 3g
Handover 3g
 
Gsm rf interview questions
Gsm rf interview questionsGsm rf interview questions
Gsm rf interview questions
 
Fast dormancy
Fast dormancyFast dormancy
Fast dormancy
 
Simplified Call Flow Signaling: 2G/3G Voice Call
Simplified Call Flow Signaling: 2G/3G Voice CallSimplified Call Flow Signaling: 2G/3G Voice Call
Simplified Call Flow Signaling: 2G/3G Voice Call
 

Similar to Cognos Macros: Situational Examples & Syntax

Cognos Macros
Cognos MacrosCognos Macros
Cognos Macros
Bryan L. Mack
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
Anand Kumar
 
Unit 5 Part 1 Macros
Unit 5 Part 1 MacrosUnit 5 Part 1 Macros
Unit 5 Part 1 Macros
Arpana Awasthi
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
braycarissa250
 
AIRLINE FARE PRICE PREDICTION
AIRLINE FARE PRICE PREDICTIONAIRLINE FARE PRICE PREDICTION
AIRLINE FARE PRICE PREDICTION
IRJET Journal
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
Mahmoud Ouf
 
IRJET- Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
IRJET-  	  Implementation and Unittests of AWS, Google Storage (Cloud) and Am...IRJET-  	  Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
IRJET- Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
IRJET Journal
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptx
skilljiolms
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
Sabi995708
 
Chapter 2
Chapter 2Chapter 2
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
Mahmoud Ouf
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1venkatam
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
Indu32
 
handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
ssuser700533
 
02basics
02basics02basics
02basics
Waheed Warraich
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
wilcockiris
 
Feature Engineering in NLP.pdf
Feature Engineering in NLP.pdfFeature Engineering in NLP.pdf
Feature Engineering in NLP.pdf
bilaje4244prolugcom
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
Rakesh Roshan
 

Similar to Cognos Macros: Situational Examples & Syntax (20)

Cognos Macros
Cognos MacrosCognos Macros
Cognos Macros
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
Unit 5 Part 1 Macros
Unit 5 Part 1 MacrosUnit 5 Part 1 Macros
Unit 5 Part 1 Macros
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 
AIRLINE FARE PRICE PREDICTION
AIRLINE FARE PRICE PREDICTIONAIRLINE FARE PRICE PREDICTION
AIRLINE FARE PRICE PREDICTION
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
IRJET- Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
IRJET-  	  Implementation and Unittests of AWS, Google Storage (Cloud) and Am...IRJET-  	  Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
IRJET- Implementation and Unittests of AWS, Google Storage (Cloud) and Am...
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptx
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
 
handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
 
02basics
02basics02basics
02basics
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
Feature Engineering in NLP.pdf
Feature Engineering in NLP.pdfFeature Engineering in NLP.pdf
Feature Engineering in NLP.pdf
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 

More from Bryan L. Mack

Custom Star Creation for Ellucain's Enterprise Data Warehouse
Custom Star Creation for Ellucain's Enterprise Data WarehouseCustom Star Creation for Ellucain's Enterprise Data Warehouse
Custom Star Creation for Ellucain's Enterprise Data Warehouse
Bryan L. Mack
 
Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...
Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...
Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...
Bryan L. Mack
 
Oracle's Listagg Function - Uses and Duplicate Removal
Oracle's Listagg Function - Uses and Duplicate RemovalOracle's Listagg Function - Uses and Duplicate Removal
Oracle's Listagg Function - Uses and Duplicate Removal
Bryan L. Mack
 
EDW PK Violation Troubleshooting Made Easy
EDW PK Violation Troubleshooting Made EasyEDW PK Violation Troubleshooting Made Easy
EDW PK Violation Troubleshooting Made Easy
Bryan L. Mack
 
SRP Implementation Success in a Complex Environment
SRP Implementation Success in a Complex EnvironmentSRP Implementation Success in a Complex Environment
SRP Implementation Success in a Complex Environment
Bryan L. Mack
 
Oracle's ListAgg Function & Pertinent Use
Oracle's ListAgg Function & Pertinent UseOracle's ListAgg Function & Pertinent Use
Oracle's ListAgg Function & Pertinent Use
Bryan L. Mack
 
ODS Data Sleuth: Tracking Down Calculated Fields in Banner
ODS Data Sleuth: Tracking Down Calculated Fields in BannerODS Data Sleuth: Tracking Down Calculated Fields in Banner
ODS Data Sleuth: Tracking Down Calculated Fields in Banner
Bryan L. Mack
 

More from Bryan L. Mack (7)

Custom Star Creation for Ellucain's Enterprise Data Warehouse
Custom Star Creation for Ellucain's Enterprise Data WarehouseCustom Star Creation for Ellucain's Enterprise Data Warehouse
Custom Star Creation for Ellucain's Enterprise Data Warehouse
 
Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...
Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...
Extending the Admin UI: Proactively Preventing Poor BPRA Load/Refresh Perform...
 
Oracle's Listagg Function - Uses and Duplicate Removal
Oracle's Listagg Function - Uses and Duplicate RemovalOracle's Listagg Function - Uses and Duplicate Removal
Oracle's Listagg Function - Uses and Duplicate Removal
 
EDW PK Violation Troubleshooting Made Easy
EDW PK Violation Troubleshooting Made EasyEDW PK Violation Troubleshooting Made Easy
EDW PK Violation Troubleshooting Made Easy
 
SRP Implementation Success in a Complex Environment
SRP Implementation Success in a Complex EnvironmentSRP Implementation Success in a Complex Environment
SRP Implementation Success in a Complex Environment
 
Oracle's ListAgg Function & Pertinent Use
Oracle's ListAgg Function & Pertinent UseOracle's ListAgg Function & Pertinent Use
Oracle's ListAgg Function & Pertinent Use
 
ODS Data Sleuth: Tracking Down Calculated Fields in Banner
ODS Data Sleuth: Tracking Down Calculated Fields in BannerODS Data Sleuth: Tracking Down Calculated Fields in Banner
ODS Data Sleuth: Tracking Down Calculated Fields in Banner
 

Recently uploaded

做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project PresentationPredicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Boston Institute of Analytics
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
Tiktokethiodaily
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
ewymefz
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
ahzuo
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
Oppotus
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 

Recently uploaded (20)

做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project PresentationPredicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 

Cognos Macros: Situational Examples & Syntax

  • 1. S I T U A T I O N A L E X A M P L E S A N D P R O P E R S Y N T A X F O R V A R I O U S C A S E S B R Y A N L . M A C K Cognos Macros
  • 2. Why Do We Need Macros? In Cognos, we dynamically filter data based on prompt values input by the user. When using Custom SQL for a report’s source, Cognos provides filters for us to filter data. But what exactly is it filtering?
  • 3. Why Do We Need Macros? Refer to the following 2 SQL scripts in SQL Developer:  Query 1:  Query 2: The only difference in Query2 is the academic_period filter in the nested query; Query2 correctly filters our result set, as our desired output count is 2524.
  • 4. Why Do We Need Macros? Our first SQL Script is embedded to Cognos as a Query, minus the academic period filter: Then a filter is added to the query via Cognos
  • 5. Why Do We Need Macros? If we use term 201320, and export our result set to Excel, we can see that we have 12148 results (the top 2 rows in Excel are header rows) As we mentioned earlier, this is not our desired output.
  • 6. Why Do We Need Macros? Here is the SQL Cognos has generated: The academic_period filter is being placed incorrectly within the query.
  • 7. Why Do We Need Macros? Let’s revisit slide 3’s results: Query 1: Query 2: Shouldn’t we be limiting this to 2524 results? Cognos is not applying the filter to the nested query
  • 8. What is a Cognos Macro? A Cognos macro allows you to place user-selected prompt values wherever you’d like within custom SQL. The macro allows you to manipulate the prompt values where necessary, and use them for more precise filtering and processing. In our example, we want the filter to be placed in the nested query rather than the outmost query.
  • 9. Proof of Concept We can filter the prompt values wherever we desire, in this case, within the nested query: We can see we now return 2524 rows The macro worked and our results are correctly filtered. You can see the macro in the SQL – but how does it work?
  • 10. Macro Syntax #prompt(ParameterName,Datatype,Defaultvalue,PreText,Sou rce,PostText)# ParameterName: Mandatory. This is what you named your prompt value’s parameter. Datatype: Optional. The default value is ‘string’. Prompt values are validated. In the case of strings, the provided value is enclosed in single quotation marks and embedded single quotation marks are doubled. Defaultvalue: Optional. Value if the user makes no selection from an optional prompt Pretext: Optional. Text to use before displaying the option the user inputs with the prompt. Example: This is the open-parentheses when using #promptmany for an IN statement (we’ll get to that in a bit) Source: Optional. The value(s) selected in the prompt Posttext: Optional. Text to use after displaying the option the user inputs with the prompt. Example: This is the close-parentheses when using #promptmany for an IN statement
  • 11. Ways I’ll Demonstrate Macros Using Oracle join syntax, I will demonstrate all of the following macro scenarios.  Inner Join (Mandatory Prompts, Optional Prompts)  Outer Join (Mandatory Prompts, Optional Prompts)  Conditional Inner/Outer  If optional prompt used – use inner join  If optional prompt ignored – use outer join  Date/Date Range (Mandatory Prompts, Optional Prompts)  For use within a function  Equal Operator (=) vs IN statement  LIKE clause  HAVING clause
  • 12. Ways I Will NOT Demonstrate Macros Many! There are countless combinations of inner join, outer join, mandatory/optional prompts, single/multi select, characters/numbers/dates, etc. etc. etc. I can’t possibly demonstrate every way to do this, so I will try to build up your base knowledge so you can figure out scenarios I have not demonstrated. I will also not be using ANSI join syntax, I will be using Oracle join syntax
  • 13. Inner-Join Mandatory Macro Compare characters (=) <field> = #prompt('parm_multi_source')# Compare characters (in) <field> IN (#promptmany('parm_carrier')#) Real example from a Cognos report:
  • 14. Inner-Join Optional Macro Compare Characters (=) <field> = (#prompt('parm_carrier','string',’<field>’)#) Let’s say the field is “myfield” and the user selects the prompt value “I Hate Cognos”. The generated SQL will be: myfield = ‘I Hate Cognos’ If the user does not use the optional prompt, the macro will generate the following SQL: myfield = myfield Note: You can convert to “IN” by changing the equal to the word IN, and change “prompt” to “promptmany”
  • 16. Outer-Join Mandatory Macro Follow the same logic as Inner-Join Mandatory, just add the plus sign for Oracle’s outer-join logic and s.spriden_id(+) = (#prompt(‘myparam')#) and s.spriden_id(+) IN (#promptmany(‘myparam’)#)
  • 18. Outer-Join Optional Macro Compare Characters (=) This will build out the entire AND statement for you #prompt('parmYEAR','string','and 1=1','and pdrhioc_year(+) = ')# Read this as: parmYear is my string parameter used in my prompt, when the user doesn’t use the prompt, insert the text “and 1=1”, when the user uses the prompt insert “and pdrhioc_year(+) = “ followed by the value they input. Compare Characters (IN) Option 1: build out the entire AND statement #promptmany('parmYEAR','string','and 1=1','and pdrhioc_year(+) IN (','',')')# The last 3 parameters are: (1) what to insert before the prompt value (2) The prompt value itself (3) what to insert after the prompt value Option 2: This requires the macro to be within an AND statement and (a.account_entity_ind IN (#promptmany('ParameterEnt','string',sq('NotSelected'))#) OR ('NotSelected') in (#promptmany('ParameterEnt','string',sq('NotSelected'))#) ) The first part of the OR statement addresses the outer-join, the second part of the OR statement keeps the join in tact when the optional prompt is not used.
  • 20. Conditional Outer/Inner Join Macro Requirements:  Have an optional prompt  If optional prompt selected, use inner join  If optional prompted ignored, use outer join and ad.account_uid = sar.person_uid #prompt('ParameterStuAttr', 'string', '(+)', '/*', '', '*/' )#
  • 21. Conditional Outer/Inner Join Macro  and ad.account_uid = sar.person_uid #prompt(  'ParameterStuAttr', --parameter name  'string', --DataType  '(+)', --Default text (when prompt ignored)  '/*', --text to precede the prompt text when used  '', --inputs the value selected in the prompt  '*/' --text to follow the value in prompt when used  )# When the prompt is used, the macro puts /* comments around the prompt value it is inserting*/, so the code processes nothing and leaves the join (account_uid = person_uid) as inner. When the prompt is NOT used, the macro places (+) after the hard-coded join, thus creating an outer join Reminder: I am using Oracle outer-join syntax
  • 23. Date Prompts Mandatory Inner: Option 1: when using ISO 8601 date format <field> = to_timestamp(#prompt(‘parm_date')#,'YYYY- MM-DD"T"HH24:MI:SS.ff3') Option 2: when using other date format standards <field> = to_date(#prompt('parm_date')#,'yyyy-mm-dd')
  • 25. Date Range After exhaustive searching and testing, I have been unable to find a way to extract the date range values from a date range prompt with a macro, so you need to create two individual date prompts (date_from and date_to)….
  • 26. Date Range Optional Prompt Example ( (trunc(ad.entry_date) >= trunc(to_date(#prompt('ParameterEntryFrom','string',sq('NotSelected'))#,'YYYY-MM-DD')) OR ('NotSelected') = #prompt('ParameterEntryFrom','string',sq('NotSelected'))# ) and (trunc(ad.entry_date) <= trunc(to_date(#prompt('ParameterEntryTo','string',sq('NotSelected'))#,'YYYY-MM-DD')) OR ('NotSelected') = #prompt('ParameterEntryTo','string',sq('NotSelected'))# ) ) This syntax uses an OR statement for each of the two parameters. The first half of each OR block is for if the optional prompt is used, the second half is for if the prompt is not used. Note: I typed the code instead of screen shot here so I could color-code the parentheses and make the code more readable for the example.
  • 27. Date Range Mandatory Prompt Example
  • 28. LIKE clause To use a LIKE clause with optional, multi-select prompt: and eec.earn_code IN (select m.allowance from mappings m where m.deductions like ('%'||#promptmany('parm_carrier','string','bd.carrier' )#||'%'))
  • 29. HAVING clause Sometimes we need to filter on the aggregates, which is used in SQL with the HAVING clause. Suppose we have a prompt filtering on an aggregate amount that a user types into a text prompt – how would we write this in a macro? Add a caveat: this is an optional prompt having sum(ad.balance) >= (#prompt('ParameterBalance','string','sum(ad.balance )')#)
  • 31. Function on top of Prompt Value Sometimes we will get a prompt value and need to use it to calculate the proper filter. In this case, we use the prompt value (parm_s) as a parameter to a function (odsmgr.f_get_pidm) to return a different value upon which we will filter. We simply wrap the entire macro within the function call: And person_uid in odsmgr.f_get_pidm(#promptmany('parm_s','string','p erson_uid')#)
  • 32. Case Statement/Function using Date Prompt Macro Note: formatted in SQL developer for readability
  • 33. Wrapping Up I hope you find this somewhat helpful. Even if you aren’t using the Oracle RDBMS, you can use these syntax examples to create macros that work for you. If you have other concrete examples you’d like me to add to this presentation, feel free to let me know and I’ll consider adding them here.
  • 34. Thank You! Bryan L. Mack fleetmack@gmail.com