views:

897

answers:

3

I have a report that has parameters StartDate and EndDate. I would like the EndDate parameter's time part to default to the end of the day when selected from the drop down.

For instance, if a user selects 5/15/2008 from the dropdown, the value shown in the box should be '5/15/2008 23:59:59' not '5/15/2008 12:00:00'

Its pretty easy to do this in .Net using the event model and a line of code but in Report Builder 2.0, what would I need to do?

Is there code that I need to write for this or did I miss some funky expression that could handle this?

Thanks.

AboutDev

+1  A: 

Use the parameter in a DATEADD() expression in your dataset.

Rather than

...WHERE end_date = @end_date

do something like this:

...WHERE end_date = DATEADD(ms, -3, @end_date + 1)

That will go forward a day (the +1), then go back 3 milliseconds, to the last instant of the day recordable by a datetime.

Jeremy Smyth
Thanks for the feedback Jeremy. However, I can't change the value at the dataset because the time can be chosen by the end user. For instance, they may want it to be 1PM instead of 11:59PM. I just need the time to default in the textbox to the end of the day. I hope I'm making sense lol!
AboutDev
+1  A: 

It's been awhile since I've used SSRS, so bear with me. You'll have to do a little translation, but here's what I've done in the past.

When you define your EndDate parameter, create an additional parameter named EndDateEOD, after EndDate in your list of parameters. Make this parameter a hidden value, and set it to the last moment of the day, similar to the way that Jeremy calculates it.

Then you can use @EndDateEOD in your report query where you have @EndDate now.

When StartDate is selected, you could have EndDate default to its value, so that EndDateEOD will automatically be set to the end of the start date.

eksortso
I can see how that works if you want it based off the StartDate, but unfortunately, I can't get it to base off the EndDate. Thinking of it in terms of events might be helpful. On the AfterSelect event of the EndDate Calendar control, I want to set the EndDate control's DateTime value to be: Value = Value + "11:59:59". I hope that helps clear up the confusion. Thanks for trying though eksortso.
AboutDev
@AboutDev, I just altered my answer to reflect what you're looking for more closely. Hope that helps.
eksortso
Thanks again eksortso. What if the user selects '5/15/2009 07:00:00' as the start and wants to select '5/30/2009 18:00:00' as the end. In the case described, using @EndDateEOD in the query would use '5/30/2009 11:59:59' as the end which is not going to work. I think the only way to get this to work would be events but they don't exist in Report Builder 2.0 as far as I can tell.Thanks again for trying.
AboutDev
I don't currently have time to provide a complete answer. But there is no need for events here. If you sequence your parameters, hidden or not, in an appropriate order, and use the appropriate parameters in your report queries, you can probably get what you want. I'm positive that you can get exactly what you're looking for if you separated End Date from End Time, calculated and applied defaults for End Time, and combined the two to get a final @EndDT parameter. But I can't offer any more help just now.
eksortso
+1  A: 

I would suggest setting the default parameter in the Report Parameters section. You can get to this from Report > Report Parameters.

This allows you to set a non-queried default. There you can enter an expression like

=DateAdd(Microsoft.VisualBasic.DateInterval.Second ,-1,dateadd("d",1,Today))

That should give you a default for the end of today.

Edit: Really only useful for a single default value.

Nathan Fisher