.

Monday, June 9, 2008

Passing parameters and other options directly through a URL in Reporting Services

Passing parameters and other options directly through a URL in Reporting Services

Problem
Reporting Services has many great built in features, but accessing them externally can be tricky. Suppose you wanted to pass a variable directly within a URL? Wouldn't it be great if you could provide a URL from a website or email that renders a report directly in Excel? Do you need to display a report (perhaps a chart) while hiding the reporting toolbar? Let's take a look at these items as well as a few others and how you can use parameters in your URL to change the report behavior.

Solution
Follow these steps to discover various solutions to these and other issues.

Solution setup:

For this demo we will be using the same sample database I used in my tip on drill down techniques, (Follow the instructions in the "Sample Data" box.)


Create a new report using the VISIBILITY_EXAMPLE_TABLE as a datasource. Use the following SQL statement as the report's first dataset:

SELECT ProductCode, ProductName, ProductColor, QuantityAvailable, SupplierName, SupplierRegion
FROM VISIBILITY_EXAMPLE_TABLE





From the Layout tab, add the six fields to a new data table.



Add a second dataset to the report and call it AvailableColors.



Enter this for the SQL statement of the new dataset:

SELECT DISTINCT ProductColor
FROM VISIBILITY_EXAMPLE_TABLE
ORDER BY ProductColor

Return to the first dataset and add the following line:

WHERE ProductColor=@ProdColor

The entered dataset should look like:

SELECT ProductCode, ProductName, ProductColor, QuantityAvailable, SupplierName, SupplierRegion
FROM VISIBILITY_EXAMPLE_TABLE
WHERE ProductColor=@ProdColor


From the Report menu, select Report Parameters. In Available values, select From query, and change the Dataset to AvailableColors, and select ProductColor in both the Value and Label fields. Leave the Default to Null. The entire Report Parameter screen should like this below:



Now save and publish the report to your Reporting Services web server. Access your report from the web server using the Report Server (not the Report Manager).

Your browser screen should look like this before clicking the report. (The name of my server is Zorro. Henceforth, replace "Zorro" with the machine name of your SQL server.) The name of my report is called "zPass_Params_with_HTML". You can name your report whatever you like.



When you first run the report, you should be prompted for a parameter:



Just to try it out, select a parameter and run the report.

As long as everything works we're ready to have some fun....

Passing the parameter entirely through HTML

Start over with your browser at the ProdColor prompt. Instead of choosing the color from the dropdown, add the following at the end of the URL:

&ProdColor=Green.

It should look like this:



DO NOT click the View Report button, but instead, click the go button in the browser. You should get the same results as if you used the dropdown within the report. This should give you the idea that you can programmatically pass parameters from another program or web site.

No comments:

.