Sorry for not posting any new OpsMgr posts lately, but I’m just too busy right now. Hopefully I’ve some more time in the future, because I’ve quite some things to blog about. But today I was creating a Custom OpsMgr Report in Microsoft Visual Studio for a customer and needed to have some Default Parameters for this Report.
This Report has only two parameters Report Year and Report Month, because this Report only needs to show data for a whole month. So if you want some Default Year and Month values for your Report Parameters you need to do this in Visual Studio:
- Go to Layout Tab and select Report – Report Parameters
- Select the Parameter you want to create a Default value for (in my case ReportYear)
- Select Non-queried Default Value and use the next function:
This will create a Default ReportYear Parameter of ‘2009’ using the NOW() Scalar Function which returns the current system date and time. And by using DatePart you get an integer representing the specified datepart of the specified date.
- For the ReportMonth Default value you can use the next Function:
=cint(DatePart(“m”,Now())-1) which return the previous month.
You could use those Report Year and Month Parameters in your SQL query like this example:
Off course in your Report query you would not declare the @ReportYear and @ReportMonth variables but use the (Default) Parameter values 😉
The result of using Default Parameters in a Report is 2009 as ReportYear Parameter and 5 as ReportMonth Parameter (I changed it manually to 6 because in May I did not any data ;-))