Friday, March 23, 2012

reporting services parameter problem

I have a report that uses as available values for a parameter a query. My problem is that the query return a list of available months, however, sometimes, i would like the user to choose null when they want to see all months in the report. but the query does not have a month null so null is not allowed.
Is there anything I can do? I cannot add a null record in the table itself.
thank you, dreyYou can either allow null for a parameter or use a UNION to add All Months to the available options. (Adding All Months tends to give a better end-user experience.) Note that the following query (because of the UNION) isn't valid in the graphical query designer. You'll be prompted to switch to the generic query designer. You'll have to modify the query to match your particular DB schema.

SELECT MonthNumber, MonthName
FROM Months
UNION
SELECT -1, 'All Months'

Now you've got your parameter values populated. If you're using the 'All Months' option, you'll want to uncheck "Allow null values".

You should now modify your dataset query to:

SELECT column1, column2, column3
FROM table1
WHERE (MonthNumber = @.MonthNumber OR @.MonthNumber = -1)

If you select a month, you will get the appropriate data back for that month. If you select All Months, then MonthNumber = -1 will always be false (since -1 isn't a valid month number), but the second part will evaluate as true for all months.

Hope that helps.

No comments:

Post a Comment