views:

3003

answers:

5

I'm working on a report in Reporting Services and I can't figure out why I'm having trouble with Non-queried report parameters.

I'm trying to get the current year and have tried:

=YEAR(TODAY())    
=DATEPART("yyyy",TODAY())

I have also tried TODAY instead of TODAY()

All of these seem to break the Year dropdown on my report. I thought if something was wrong it would just not get the correct default... but nope, it breaks the whole field.

Any thoughts? articles?

UPDATE:
Wait, wait, wait... the weirdest thing. The Year parameter is the second parameter of this report. And its grayed out (with no value) UNTIL I select the first parameter (im my case "category"). Am I somehow telling the Year param to do this? or does SSRS 2005 process the params in order? I don't think I ever noticed this before.

UPDATE 2:
Please see all comments

+2  A: 

Try:

=Year(Now)

I'm not sure if this is what you need, but it worked for me. I used it to form a date string so I used =Year(Now).ToString().

Gerrie Schenck
Both of these kill the field. It does not load and becomes grayed out.
tyndall
I should add to "just make it work" I have manually typed in 2009 into the Non-queried Default Value on 5 reports. This works.
tyndall
Plain old 2009 works, but =2009 does not work. Should it? Can someone test it on their server?
tyndall
Does anyone know is this maybe related to a Service Pack fix?
tyndall
+2  A: 
=DateTime.Today.Year

should work as well.

Edit: Bruno - i have the same behavior as you are seeing. I created a sample report with a string first parameter with no default value, and a string 2nd parameter with a default of =DateTime.Today.Year. When I have the one with the default as the 2nd parameter in the order, it shows up empty and disabled.

I was able to fix this problem 2 ways: first by adding a default of =String.Empty to my first parameter, and the second way was to just change the order of the parameters.

Not sure if this behavior is by design or a bug - but like you said, I hadn't noticed it either until today when you pointed it out in your question.

Scott Ivey
This kills the field. It does not load and becomes grayed out.
tyndall
Thanks for testing this. I think this occurs because the engine has no idea whether your function is using a param that comes before it. Even if it is just =DateTime.Now.Year. So I didn't want to confuse my users. They might think my reports are now somehow broken. Solution in next comment.
tyndall
I created an extra result in the DataSet with: SELECT YEAR(GETDATE()) AS [CurrentYear]. Then change the report param to use this query for the default value. see also smb's answer +1
tyndall
+2  A: 

SSRS does process the report parameters in order - order can be important if you have dependencies between your parameters.

From MSDN: "Parameter order is important when you have cascading parameters, or when you want to show users the default value for one parameter before they choose values for other parameters."

So, it will always wait until you have a default value for your first parameter or you enter the first parameter's value, before it processes the next one, and so on.

http://msdn.microsoft.com/en-us/library/cc281392.aspx

Sophia
A: 

I found the by making sure that ALL of my parameters had at least some default value, then you will not experience they greyed out datetime picker. So, every parameter before your datetime paremeter in order needs to have a (default) value or it will not work.

A: 

Def due to order of evaluation of parameters.

Simple workaround ; in the parameters tab you can change the order of the parameters - this will move the date pickers to the top of the list and are then enabled straight away, on my server at least.

Someone raised the issue of basing a date filter on a queried default value - if you do this, you will notice a very annoying knock-on effect of getting screen refresh any time the dates get changed, before you have a chance to requery the reports.

dan