views:

206

answers:

2

Hello....

I have an SSRS report that contains several subreports. The user has the ability to select/deselect which subreports they want to produce using several Boolean parameters. If a subreport is deselected then it is not rendered by setting the Visibility property. However, the DataSet associated with the de-selected subreport still executes causing the execution time to take longer than expected.

Is there any way to tell a dataset on a subreport or Tablix not to execute based on a Parameter selection?

Thanks

A: 

Yes. Just check the parameters in each dataset and use an IF/ELSE construct to return actual data or dummy data of the same shape to prevent errors. Assuming your parameter is named @ShowThisData then you can do this:

IF @ShowThisData = 0
    SELECT '' FIELD1, '' FIELD2, <etc... to create a dataset that matches the normal output.>
ELSE
    <whatever you normally do to get the data>
JC
OK cool...where do you put that conditional Code in the dataset. I tried in the Query text and it didn't like that. I looked at the filter property of the DataSet, too. Is that where it should go?
MikeTWebb
what was the error?what's in your dataset's query text now?
JC
the error id "ORA-00900: invalid SQL statement" if @Parameter = 'true' select * FROM <TABLE> where running_total_pct <= 100 order by running_total_pct
MikeTWebb
Oh Oracle. Sorry, I shouldn't have assumed MSSQL. I don't think you have quite as much power in the dataset when using Oracle. Try Mark Bannister's simpler approach.
JC
Come to think of it, you still could use a similar approach. The dataset query text can be an expression and an IIF() expression could provide different query text based on the parameter. But for basic queries, Mark's solution is far simpler I think
JC
Yeah, Oracle....I should mention that. And I tried the IIF in the expression and got a similar result. The same ORA-00900 error. I'll give Mark's answer a try. Thanks
MikeTWebb
to use an expression for the query text, you need =IIF(Parameters!ParameterName.Value=True,"NORMAL SQL HERE","DUMMY SQL HERE") and then you have to make sure you properly handle any embedded double quotes in the SQL.
JC
Gotcha...thanks
MikeTWebb
+2  A: 

Include an ...AND :ParameterName = 'Y'... condition in the where clause - if your parameter is not 'Y', the query will still fire but it will immediately return 0 records.

Mark Bannister
Yes, for simple queries this should work fine, too.
JC
Cool deal...I'll give this a shot and let you know how it goes. Thx
MikeTWebb
Hi Mark...I've tried this approach and it works as far as zero rows being returned when the parameter <> 'Y'. However, the execution time is about the same. Do you suppose the query still gets sent to the server?
MikeTWebb
It will get sent to the server, but the optimiser on the server should immediately recognise that 0 records are required and return an empty dataset. What execution time are you getting?
Mark Bannister
Interesting....when I deselect al 12 reports...the executino time is ~30 seconds. When I select all 12 reports it is the same (give or take 1 second)
MikeTWebb
To be more accurate....29 seconds with all "deselected". 36 seconds all "selected".
MikeTWebb
Perhaps the delay you're seeing is network latency or server response time rather than query execution time.
JC
Could very well be...the 29 Seconds is consistent. So, that makes sense. Tahnks again
MikeTWebb