COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: esar on 23 May 2017 01:31:29 PM

Title: Getting Report SQL during Runtime
Post by: esar on 23 May 2017 01:31:29 PM
Hi Experts,

Is it possible to get the report SQL displayed in report viewer while running the report?

Title: Re: Getting Report SQL during Runtime
Post by: Drisya on 25 May 2017 03:59:55 AM
In report studio, from Tools menu select 'Show generated SQL/MDX'.
You cna get the report SQL but on run time this will be changed based on your selected values in prompt.

Hope this helps.

Drisya

https://cognostips.wordpress.com/
Title: Re: Getting Report SQL during Runtime
Post by: bdbits on 25 May 2017 04:52:45 PM
I may be wrong, but I think the idea is to display the SQL on the report. Which I am not aware of a way to do that out of the box.
Title: Re: Getting Report SQL during Runtime
Post by: esar on 07 Jun 2017 09:41:53 AM
Yes.. You are right bdbits.. the intent is to get the report SQL in report output. It is possible through SDk, but i wanted to see if there is any simpler way to achieve this.

Any help would be much appreciated.
Title: Re: Getting Report SQL during Runtime
Post by: CognosPaul on 07 Jun 2017 09:58:21 AM
One thought that I can't test.

The audit table cogipf_nativequery contains the full query if you have logging set up for it.

Create a new page at the end of your report, and call that with:
select * from cogipf_nativequery where COGIPF_REQUESTID = #sq($requestID)#

I can't test this at my current client because, in their infinite wisdom, they've decided not to use the native Cognos audit functionality. Let me know how it goes.
Title: Re: Getting Report SQL during Runtime
Post by: esar on 07 Jun 2017 10:11:24 AM
Quote from: CognosPaul on 07 Jun 2017 09:58:21 AM
One thought that I can't test.

The audit table cogipf_nativequery contains the full query if you have logging set up for it.

Create a new page at the end of your report, and call that with:
select * from cogipf_nativequery where COGIPF_REQUESTID = #sq($requestID)#

I can't test this at my current client because, in their infinite wisdom, they've decided not to use the native Cognos audit functionality. Let me know how it goes.



You are amazing... Blew my mind  :D ... Thank you so much... This saves so much work for me..

And Btw love your Blog... Genius
Title: Re: Getting Report SQL during Runtime
Post by: esar on 07 Jun 2017 10:19:41 AM
Quote from: CognosPaul on 07 Jun 2017 09:58:21 AM
One thought that I can't test.

The audit table cogipf_nativequery contains the full query if you have logging set up for it.

Create a new page at the end of your report, and call that with:
select * from cogipf_nativequery where COGIPF_REQUESTID = #sq($requestID)#

I can't test this at my current client because, in their infinite wisdom, they've decided not to use the native Cognos audit functionality. Let me know how it goes.



Just one thing.. the reason why i need the SQL is the give it to the users in case the query takes more time and if the data returned is huge..  So they can take the SQL and directly run it in toad or SQL developer. But in your approach, the query will have to run in the database before i can see the SQL, which kind of breaks the actual purpose.

Any way to overcome it????
Title: Re: Getting Report SQL during Runtime
Post by: CognosPaul on 07 Jun 2017 10:25:50 AM
Two thoughts.

1. Try setting the query hint: "Maximum Rows Retrieved" to 1. No idea if that will still generate the query.
This won't work - it fails with a report error.

2. Add this detail filter:
'remove this filter'='before pasting in toad'
The Oracle optimizer should be smart enough to see that filter and stop query processing before it does anything heavy.
Title: Re: Getting Report SQL during Runtime
Post by: esar on 07 Jun 2017 10:33:59 AM
Quote from: CognosPaul on 07 Jun 2017 10:25:50 AM
Two thoughts.

1. Try setting the query hint: "Maximum Rows Retrieved" to 1. No idea if that will still generate the query.
2. Add this detail filter:
'remove this filter'='before pasting in toad'


1st option will throw cognos error. But second option sounds promising. I can parse the SQL using jquery and remove that filter condition in output.
Title: Re: Getting Report SQL during Runtime
Post by: CognosPaul on 07 Jun 2017 10:46:17 AM
use the replace function in the select - no jQuery needed.
Title: Re: Getting Report SQL during Runtime
Post by: esar on 09 Jun 2017 01:28:56 PM
Quote from: CognosPaul on 07 Jun 2017 10:46:17 AM
use the replace function in the select - no jQuery needed.


Thank you Paul. Appreciate your timely help.