Question

I am working on an application which needs to produce reports containing the data of a datagrid as it is (including multiple dynamic filters). My filtering currently gets a result set from an SQL query which causes the following problem: I cannot send multiple where filters to either SSRS or Crystal reports because it won't let me bind the fields to the dynamically generated query.

This is my question: Is there any way to create reports with an unlimited amount of conditions in the where statement or to create a stored procedure with a dynamic where clause so that I can use it with either CR or SSRS? And if not, is there any reporting engine that would allow me to concatenate that filter in the where clause?

Note: I'm using C# 4.0 along with SQL Server 2008 Express (w/SSRS installed) and the Crystal Reports for Visual Studio 2010 library by SAP.

Was it helpful?

Solution 2

After some more digging in Crystal Reports, I found out that with commands and parameters it is possible to concatenate a part of a where statement into the query, which somewhat solves my problem. This isn't how reporting should be done, so I'll try to find a cleaner way to do this. SSRS just does not support this, in a Stored Procedure case, you would have to make the whole query a string that you execute, and then query from that Stored Procedure result as if it was a table, which frankly isn't worth the trouble.

OTHER TIPS

A simple trick to add filters when they are defined is to add the following code in your where clause :

where (@param is null or @param = field)

So, when the @param is not defined (null), then the filter is not applied. You can build a longer where clause, like :

where (@param1 is null or @param1 = field1)
  and (@param2 is null or @param2 = field2)
  and (@param3 is null or @param3 = field3)
  and (@param4 is null or @param4 = field4)
  ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top