Start Date Range parameters in SSRS - reporting-services

When I set up my SSRS report originally I set it up to look at the current day so my where clause in my query was:
Where
trunc(START_DAY) >= current_date -1 And
trunc(START_DAY) <= current_date
Now I want to add parameters to select just the "START_DAY."
How would I go about setting this up?

It sounds like you're using Oracle where the TRUNC function is converting your datetime to a date.
In this case you would set up a date parameter in SSRS. You can add a default date of today or yesterday.
Then, in the SSRS dataset, add the parameter to your Oracle query.
Where TRUNC(START_DAY) = :DATE_PARAM
You may need to map the parameter manually in the Parameters tab of the dataset.

Related

Are SSRS parameters fixed while generating a report?

I have been using the following code within my SQL queries:
DECLARE #CurrentDate DateTime = Getdate()
I then reference #CurrentDate instead of using the Getdate() function multiple times within the same query. This is useful because the value of #CurrentDate doesn't change during execution of the query.
However, I have started converting some of these variables to parameters set by SSRS. This allows the user to change the parameter #CurrentDate which is useful for various reasons. Typically the default value is set to "=Now()" or some expression containing the Now() function.
At what stage are these parameters calculated and is there a "correct" way to calculate them if I want parameters to be consistent with one another?
I'm trying to figure out if I should have one parameter for the current date and then reference that in the calculation of my other parameters or if this will produce the same inconsistencies (or worse inconsistencies) as simply using Now() within the expression for each parameter.
It all depends on what you mean by "consistent". Take these two scripts for example:
--Method #1
UPDATE tracker.shipment SET delivery_date = GETDATE() WHERE delivery_id = 1;
WAITFOR DELAY '00:00:01';
UPDATE tracker.shipment SET delivery_date = GETDATE() WHERE delivery_id = 2;
--Method #2
DECLARE #current_date DATETIME = GETDATE();
UPDATE tracker.shipment SET delivery_date = #current_date WHERE delivery_id = 1;
WAITFOR DELAY '00:00:01';
UPDATE tracker.shipment SET delivery_date = #current_date WHERE delivery_id = 2;
This is a pseudo script to update a tracking system to show when delivery was made. I would argue that the first version is more "consistent" as it records when the update was actually made, and not an arbitrary date/ time from when the stored procedure was first entered.
Let's pretend that there's another system constantly checking for delivery items that have a delivery date added, then makes the actual delivery, or that the code immediately before each delivery update does something to trigger the actual delivery. In this case it would be much less consistent to use the second method, as this would record deliveries as being made for some time in the past, before they actually were delivered.
As far as I am aware the parameter sent by SSRS will be evaluated to determine the server time on the reporting server at the point where the user clicks the "View Report" button. So every parameter that has Now() will end up with the same date time, but this might be slightly out from the SQL Server if your servers aren't exactly in synch.
Does this actually matter? Well that depends entirely on what you are doing with the date/ time you are passed I guess. When your users enter a custom date/ time are they entering a date or a full date/ time? I imagine they only enter a date, so this is automatically converted to having a 00:00:00.00 time component?
Basically I would need more context to be able to give a fuller answer to this.
Just create a datetime SSRS parameter and set the default value to NOW(). Then it will assume everything, but users can opt for a different date. Note also that SSRS uses DATETIME parameters, but for a lot of my reports I actually use a string parameter field which I CAST to DATE to avoid losing data between hours that the user isn't expecing:
WHERE CAST(StartDate AS DATE) > CAST(#StartDateParam AS DATE)

Today() and Now() functions return Modified Date instead of current DateTime in SSRS

I am using the "Today()" function as the default value in SSRS parameters to set start and end date ranges. On the reports that have been deployed these parameters are returning the date the report was deployed (Modified Date) instead of today. On text boxes or labels that use the Today() expression it is returning today correctly.
I know that i can get default values from a query (GetDate()), but I'd like to use Today() as it was intended...

Set Default parameter in SSRS from a dataset

How can i set the default parameter in SSRS using a value from Dataset?
I want the default parameter to be the previous month date that is selected from a table tblPeriod(per_id, lastDay)
tblPeriod stores the months in a set of 20 year with last day storing the last day in a month.
e.g
2000, 31-Dec-2016
1999, 30-Nov-2016
I wrote this SP getPeriod which works like this-
select per_id, lastDay , (select per_id from tblPeriod where lastDay < getDate()) as maxDate from tblPeriod
The report populates a drop down with all period values
How to make the default date as previous month end date using the maxDate value returned by the Stored Procedure?
<ReportParameter Name="period">
<DataType>Integer</DataType>
<Prompt>Period</Prompt>
<ValidValues>
<DataSetReference>
<DataSetName>Periods</DataSetName>
<ValueField>per_id</ValueField>
<LabelField>lastDay</LabelField>
</DataSetReference>
</ValidValues>
</ReportParameter>
I would also like to know how to set the top most item in a parameter drop down as the default selected item in the report
Click on default value option then click on function then you can write a function to get the date you are wanting like [#parameterName] will get the entered parameter then use some of the math function to modify it like you need. Your problem is hard to solve without seeing what you are doing in the GUI and you will have to get pretty creative to solve it.
Sorry I can't be of more help. If you add some screen shots I may be able to help more.

sql query to get a scheduled report to run for that curent month only

I have an SSRS 2005 report that has a dataset for to an Oracle database. The report that i have essentially just pulls all data back from an audit log. This report works perfectly fine and i have scheduled thi to run and send an email using the new subscription method within SSRS.
The only issue i have is i want the report to run on the last day of the month (its set up to do this alreday) and run the report based on that month only. Getting the report to run specifically for a month is what im unsure on? I though i would be able to set parameters within the report but these only enable my user to select a calendar date?
Is there a DATEADD or DATEPART type of function i can use to complete this task?
Regards
B
Best bet would be to set up a dynamic date default for the date patameter at the report level, and set up the subscription to use this default value, so whenever the subscription runs it would automatically have the appropriate date.
Probably the easiest thing to do is set the parameter as the current date, if that would work, e.g. something like =Today(). So that will be calculated whenever the subscription runs.
You can set the default value for whatever you need; first day of the current month, etc. You should able to set whatever value you need without too much trouble.
So for the first day of the month something like:
=DateSerial(Year(Today()), Month(Today()), 1).
Users running the report ad-hoc could just reset the parameter as required.
I'm assuming the report handles the amount of data to return correctly assuming the right data parameter is sent.
2 Parameters #DateFrom and #DateTo
Default Value for #DateFrom that outputs the first day of the current month:
=DateAdd("d",-Day(Today())+1,Today())
Default Value for #DateTo that outputs the last day of the current month:
=DateAdd("d",-Day(Today())+1,DateAdd("m",1,Today()))

Report Builder - Set datetime parameter

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
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.
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.
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.
You can do something like this:
=CDate(Parameters!StartDate.Value + " 23:59:59")
The part of Parameters!StartDate.Value can be any date but not the EndDate.Value itself. Eg:
- Today()
- Last day of the month from start date:
=CDate(DateSerial(Year(Parameters!StartDate.Value), Month(Parameters!StartDate.Value) + 1, 0)+" 23:59:59")
Hope this help.