views:

35

answers:

2

Hi guys, Im trying to create a report in SSRS. The report calls a stored procedure for its data. I want to display the data in a table. But the thing is, the result from the stored procedure differs from time to time, because every customer has its own 'template'. This means the result for customer A could be :

AccountNumber | CustomerID
1234567890           0987654321
1579086421           1234565465
......................          ....................

and for customer B could be:

CustomerName | Address
Customer B          Teststreet 1
Customer Test     Teststreet 2
......................      ....................

There are 50 different columns to choose from. The order of the columns is also editable. My stored procedure takes care of this. The only thing I want is to put the resultset of the storedprocedure 1:1 in my report (header+body). Do you guys know how to do this?

If thats not possible, is there a C# solution to this? I.e creating a report object in C#, adjust settings etc.

Thanks

+1  A: 

You can create the SSRS report dynamically based on the data set returned by the stored procedure. The report format (RDL) is documented and its an XML format. So you can use System.XML namespace to generate RDL. Alternate (and unsupported) way is to refer RDL object model assembly (Microsoft.ReportingServices.RdlObjectModel) - you can locate the assembly on SSRS 2008 server machine and copy it on your local machine. It offers an object model to read/generate RDL.

I have adopted approach where RDL is generated (as XML) dynamically based on the data-table and then publish the RDL on SSRS server using web services API.

VinayC
And how do I create a dynamic report based on the data set returned from the stored procedure? Could you explain how? Via reportdesigner?Generating RDL file isnt really a solution, since 100+ ppl are working simultaneously with the webapp that should generate the rdl-file, which means 100++ (per day) rdl files are to be saved on the server.. Or do I get you wrong?
MaxiBlue
As said earlier, you need to generate xml for RDL file. For example, create a sample column report in designer and open the RDL in text editor. By this way, you will understand how report columns and fields gets mapped in RDL file. Now based on columns from data set, you need to generate an RDL file. In our case, we did generate RDL files but did not publish them on SSRS server - rather used ReportViewer control in local mode to display them. Generated RDL files were created in temp directory and gets periodically cleaned up.
VinayC
Continuing on, number of RDL files generated will be based on usage. For example, if you can have only certain number of combinations then you can generate those RDLs as templates and use them as and when needed. If that's not feasible then you have to generate RDL for each possible combination of columns (and orders).
VinayC
I fixed it :). I wrote a C# app which dynamically generates the RDL file, and loads it with ReportViewer
MaxiBlue
A: 

One solution might be to modify your SP so that the data returned looks something like:

ColNameA       DataA       ColNameB    DataB
AccountNumber, 1234567890, CustomerID, 948477586
AccountNumber, 5466584426, CustomerID, 458852244

Then, in SSRS drag out a table. Create a group on ColNameA. In that Group Row, place the Field ColNameA in the first Column, place ColNameB in the second column.

In the Details Row, place DataA in the first column, and DataB in the second column, and should look like this:

alt text

The sample query i used was:

select 'AccountNumber' as ColNameA, 1234567890 as DataA, 'CustomerID' as ColNameB, 0987654321 as DataB UNION 
select 'AccountNumber' as ColNameA, 5546488393 as DataA, 'CustomerID' as ColNameB, 4747599393 as DataB

Getting the names of the Columns (AccountNumber, CustomerID or CustomerName, CustomerAddress) will be the key. You can get them via:

select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'my_table_name'
D.S.