COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: laxmanrao83 on 11 Feb 2013 03:37:37 AM

Title: How to pass null values in macro in SQL Query in Report Studio
Post by: laxmanrao83 on 11 Feb 2013 03:37:37 AM
Hi All,
In my report, I have Date propmts(From Date & To Date) and Exception Code prompt. By default I want to display current date's data and for all Exception codes(so its a optional prompt).
I am using SQL Query to fetch the data from the table and I must use all the filters in the SQL Query itself. So I am using macro in the SQL query.

Select Exception_Code, Job_Name,Table_Name,Survey_Dt
where Survey_DT between #prompt('param_From_Dt','token','current date')# and #prompt('param_To_Dt','token','current date')#
and Exception_Code = #prompt('param_Exception_Code','string','B201')#.

In order to make this optional I have passed a default value as B201. However, when the report should run for the first time, it should display all the data for the current date for all Exception codes.
FYI--Database is DB2.

How to incorporate this in SQL query?

Title: Re: How to pass null values in macro in SQL Query in Report Studio
Post by: CognosPaul on 11 Feb 2013 04:09:16 AM
Writing from my phone so please forgive my brevity.

Make the entire and exception part of the macro, specifically in the fourth parameter.

Select Exception_Code, Job_Name,Table_Name,Survey_Dtwhere Survey_DT between #prompt('param_From_Dt','token','current date')# and #prompt('param_To_Dt','token','current date')# #prompt('param_Exception_Code','string',' ',' and exception_code=')#

If the parameter is empty then it will return a space to the sql. If not it will put the filter in.
Title: Re: How to pass null values in macro in SQL Query in Report Studio
Post by: ravikrsingh on 11 Feb 2013 04:42:53 AM
It works  :)..I tried this..Thanks Paul
Title: Re: How to pass null values in macro in SQL Query in Report Studio
Post by: laxmanrao83 on 11 Feb 2013 04:45:39 AM
Thanks Paul..

It's working fine

Thanks very much