SSRS 2008R2 Report parameter with Now() default not auto-refreshing - reporting-services

System - SSRS 2008R2 using report builder 3.0 (or BIDS if you think the answer lies there)
Objective - Create a report that displays sales data from the past 24 hours for each sales region. The report needs to refresh every 10 minutes, and always show the last 24 hours from the last refresh. However - the users still need to have the ability to change the time frame.
What did I do?
Built a report that shows sales data for a single region depending on 3 parameters: StartTime, EndTime, RegionCode. Lets call it RegionalSales
Built a master report that includes multiple subreports of RegionalSales. the master report has 2 parameters - StartTime (with a default value dateadd("h",-24,Now())) and EndTime (with a default value Now()). I am sending StartTime and EndTime to the subreports, and every subreport is assigned it's own region.
I've set the Auto-Refresh property of the master report to 600.
Results -
At first everything seems perfect - the master report loads, and the data shown is correct for the loading time (let's say 22:08). However, after the auto-refresh (that occures at 22:18) the data is still correct as to 22:08.
The problem is that on the first load of the report the parameters get their default values as I stated (StartTime = 10/12/2011 22:08 & EndTime = 11/12/2011 22:08).
However, on the auto-refresh instead of the paramters updating (So I'll get StartTime = 10/12/2011 22:18 & EndTime = 11/12/2011 22:18) I still get the old values (StartTime = 10/12/2011 22:08 & EndTime = 11/12/2011 22:08)
Any thought on why, and how can I change this?
Thanks!

If I understand correctly...
Unfortunately, report parameters get their values only at the first load unless the user manually clicks the View Report button.
To get around this, I'd try converting the date parameters to not use default values, but rather get their values from a query and use the equivalent of GETDATE() for your RDBMS. If I'm not mistaken this will require you to add another DataSet to your report... but it won't really be a dataset since the query for it will simply be SELECT GETDATE() [or the equivalent for your RDBMS] and whatever transformations you need to do for that.

Related

In SSRS, a Date Time parameter on Preview is not matching the deployed report

In SSRS, a Date Time parameter on Preview is not matching the deployed report. Is this something someone else has encountered? The RDL code is identical. Is it the fact that, sometimes, a local preview is just a simulation of functionality? Is it because the display in preview sometimes uses cached data?
I have a SSRS report that, when I preview it in Visual Studio locally, the date shows as 2/10/2019 but when the RDL code is deployed on the server, the date shows as 2/7/2019.
The date time variable is based on a parameter on the report, called rundate, and it has a Default Value of 2/10/2019.
So I think the same thing should happen on the Report Server that happens locally in preview mode.
The report has four datasets and, as a test, I have set each four to have the SQL line that sets the rundate value like so:
SET #rundate = '2019-02-10'
but on the report server, when I load the report, it throws this error:
Must declare the scalar variable "#rundate". Must declare the scalar variable "#rundate".
It is in a cascading tabbed error message that looks like this:
An error occurred during client rendering.
An error has occurred during report processing.
Query execution failed for dataset 'ThirdDataset.
Must declare the scalar variable "#rundate". Must declare the scalar variable "#rundate".
So, why does it run locally and not on the server? The "ThirdDataset" is a false name I have given here. The actual name is redacted. But, I have noticed that this would be the first dataset run if they are run alphabetically. So this leads me to the question: why doesn't the report recognize this as a parameter and why does it complain that it is not declared?
============
UPDATE:
I have set the rundate to be part of a data-driven subscription in a report like so:
SELECT convert (date, DATEADD (DAY, -2 , SYSDATETIME())) as rundate
Which is two days ago. Since it is 2/11/2019 today, the rundate parameter passed to the SSRS report on the server should be 2/9/2019.
For fun, to test this out, I set the Default Value rundate parameter to be 8/8/2018 in hopes that the data-driven report would set it properly.
In preview mode locally on Visual Studio, a textbox that set to show the [#rundate] Expression shows 8/8/2018 which is what I would expect, but the Datasets are designed to run off this parameter. Since there is nothing that the sql should retrieve from the database that is that old, the graphs and charts in preview mode should turn up completely empty. Why do they show data?!
Next, let's see what the emailed subscription alert says. It had the date of 2/11/2019 12:00:00 AM. If the data-driven subscription ran like it shouold ahve run, it should of had the date of 2/9/2019 from
SELECT convert (date, DATEADD (DAY, -2 , SYSDATETIME())) as rundate
Why did this not work?
On the SSRS server, the RDL file has a parameter default value of 2/11/2019 12:00:00 AM but why did the report get THIS default value? What am I doing wrong and how can I fix this?
As a test, I set this default date/time parameter to 12:12:34 for its time to see what would happen. It reveiled that, yes, this is the date time stamp that is being sent to the report. So I unchecked the "Has Default" box
Then, I noticed in the Step 5 of the data-driven subscription I could not advance to Next > without making a small change:
So, what should happen? Will it show the wacky 8/8/2018 value? Will it show the date from two days ago?
Default values for report parameters are deployed only once to the report server, and then they keep their default value after subsequent deployments. This is so that default parameter values used in development don't overwrite the desired parameter defaults on the production server.
So it looks like when the report was first deployed, #rundate had the default value 2/7/2019 but has since been changed on the local report to 2/10/2019. Go into your report server, find the report and go into the Report Parameters section to edit the parameters and change the default value to what you want it to be (deleting the report from the report server and re-deploying it with the updated parameter will have the same effect, but note that the parameter will maintain that default value going forwards). Alternatively, set the report parameter using an expression so that it is continually up to date.
Regarding updating your parameter value in the Sql statement using the SET statement, you can't actually do it that way - you need to set it in the report's parameter list so that SSRS can set the parameter value. Consequently, your databse server is complaining that you are trying to set the value of a local variable that hasn't been defined in your Sql statement, and thus throws an error message.
So you need to set up the Report Parameters in the report parameters section in the report designer. Your Sql can then reference your parameters like so:
SELECT * FROM MyTable WHERE SomeDate >= #rundate
The parameters normally get mapped into your dataset automatically but you might want to check this by going into the Parameters settings on your dataset to make sure. If the parameter doesn't exist there, set it up.
After lengthy trial and error, I found that the answer was to NOT have the parameter set to have a default value on the SSRS Report Server.

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)

SSRS filter date time not working

Report SSRS in window 10 and open from IE 11
my computer filter date not working (not show image calendars)
How to fixed .
thank you.
Expanding on WEI_DBA, it looks like you need to set the default value of your Start Date parameter to ="3/16/2017 0:00:00" since your date format has months and days reversed.
Note that this can be confusing when you have a server with a different region setting than your workstation. The report is fine to develop locally and will then generate this error when deployed to your server.
In the parameter pane, right-click on Start Date and select Parameter Properties. Find "Data Type:" in the middle of the dialog and change the drop down to be Date/Time. Do the same for End date.
A date/time parameter will will show the date picker and will ensure you are passing a properly structured date value into your dataset query, regardless of your culture/language settings.

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()))

Using SSRS Data Driven Subscription as a Data Driven Schedule

I'd like to have a data driven "schedule", meaning every report has it's unique time (stored in a table which is populated every minute) when it needs to go out.
For example: (not all fields included)
To Parameter Format NextRunDate ReportStatus
bob[at]email.com SalesRegion1 Email 1/1/2012 9:00:00 'Unprocessed'
joe[at]email.com SalesRegion2 Email 1/1/2012 9:05:00 'Unprocessed'
sara[at]email.com SalesRegion1 Email 1/1/2012 8:55:00 'Processed'
if the time is currently 1/1/2012 9:01:00 my Data Driven Subscription "where statement" would be something like...
where NextRunDate < GETDATE() -- in the past
and ReportStatus = 'Unprocessed' -- <--here is my problem
This query is run every minute. It should only pull the report for bob[at]email.com...
My problem is here:
I need to add logic that toggles the Report Status and 'Processed' once the report is sent... otherwise it runs every report every time...
Thoughts? Other ways to get this to work?
Running SQL Server 2k8 Enterprise
Thanks in advance!
If the reports are run on a similar cycle (every minute or every five minutes as in your code) you could use BETWEEN and DATEADD to subtract the number of minutes (whatever) to get to the last time you ran the report through to now.
{WHERE NextRunDate BETWEEN DATEADD(mi, -5, GETDATE()) AND GETDATE()}
I hope that helps.