"As of Date" Report logic - sql-server

I've been stuck on this issue for most of this morning...I am trying to work through a display issue with my SSRS report regarding my "As of Date". The data behind this report is loaded nightly, meaning the data is only as good as yesterdays actual date. My problem is that my report currently defaults the parameter to =#AsOfDate = Today().
However, in order for this to be accurately reflected, whenever a User wants to change the date on this report, I would need the "As Of Date" to always reflect yesterday. So if we ran this report for today 3/7/16, the Data behind the report is from 3/6/16 thus, the report should show "As of" 3/6/2016, and if they selected 2/29, on View Report, it should show As Of 2/28/16, etc.
My SQL statement in the report is using a column from my report table called CurrentDate which just holds the nightly load date. It states ...
WHERE #AsofDate = CurrentDate
Does anyone have any idea how I could accurately script this so that a User can always know that the data is from the night before?
Thank you!,

Try setting your AdOfDate to the default value for yesterday (calculated):
#AsOfDate = DateAdd(DateInterval.Day, -1, Today())
Otherwise, you could set your SQL query to do the same
WHERE AsOfDate = DateAdd(d, -1, GetDate())

Related

Dynamic dates in SSRS

I need to make a report of all patients who had an appointment last week. This report will be added to another excel with some lookups and then put into Power BI because we don't have way of connecting our sql server.
I'm trying to reduce the amount of manual work I have to do by instead of using parameters with dates, adding a dynamic date.
I have tried using TODAY, CURRENT_DATE and they all come back with an error.
I just need it to give me data for 7 days prior to the current date
Any help would be greatly appreciated.
This is what the first part looks like:
SELECT
PM.vwApptDetail.Patient_Last_Name
,PM.vwApptDetail.Patient_First_Name
,PM.vwApptDetail.Patient_DOB
,PM.vwApptDetail.Appointment_DateTime
,PM.vwApptDetail.Appt_Type_Desc
,PM.vwApptDetail.Resource_Desc
,PM.vwApptDetail.Status
FROM
PM.vwApptDetail
WHERE
PM.vwApptDetail.Appointment_DateTime >
I ended up using:
WHERE Appointment_DateTime BETWEEN GETDATE() AND DATEADD(DAY, -7, GETDATE())
and it seems to have worked.

How to create new date field using CASE in Google Data Studio

I'm creating a dashboard of marketing leads from a Data Source that has two columns of dates in it. One of the columns is historic dates that were imported. One of the columns is all new leads, with accurate dates.
I'm trying to create a new field in Data Studio for use as the Date Range Dimensions. Essentially, if historic date is null, then use new date. If it isn't null, use the historic date.
This is my current code:
CASE
WHEN Historic Date IS NULL THEN Created Date
ELSE Created Date
END
There are no errors thrown when creating the field, but when I set it as the Date Range Dimension, I get this error:
This data source was improperly configured.
Invalid argument type.
Seems that Case function has as output a string which cannot be recognized or configured as a date in google Studio. It can be a bug from Data Studio, but the fact is that I have the same problem and I solve it converting the output of case into a date format.
I have no much time to explain/expose it better, therefore I will put the function that worked for me:
todate(CASE
WHEN Status IN ("X","NMX","MX") THEN Cancel Dt cf
ELSE Confirm Dt cf
END
,'%Y%m%d','%Y%m%d')
Hope it fixes you well you or at least gives you some light/direction on how to solve it.

Validity period for SSRS reports

We have ssrs 2008 r2 rdls. I open an SSRS report and keep it open in my browser for more than 30 mins. If I now click any drill downs either through an action or goto report. I don't want the report get me that info. It should state that the report is expired.
Is there a solution already available . Do future version SQL server have a solution for this.
There not a built in way to do this natively in SSRS.
I haven't heard of anyone asking about a requirement like this before so I doubt that there's something already in the works to add it.
I don't know JavaScript enough to know whether or not you can add logic to the JavaScript URL to where it would create a blank link or link to a Page Expired page.
="javascript:void(window.open('https://na5.salesforce.com/','_blank'))"
You could create a hidden datetime parameter on the main report and set its default value to the current time: =Now(). Let's call this parameter #MainReportRuntime.
Make this same hidden parameter on your subreports and pass #MainReportRuntime through to the subreports.
Modify the SQL of the subreport to only return data when the date is within half an hour of the main report runtime and add the report expiry message when it is greater than half an hour old:
SELECT SomeField
FROM SomeTable
WHERE #MainReportRuntime >= DateAdd(mi, -30, Current_Timestamp)
UNION ALL
SELECT 'Report has expired - please rerun report to get current data'
WHERE #MainReportRuntime < DateAdd(mi, -30, Current_Timestamp)

Can the value of a subscription parameter be set to an expression when creating an SSRS report subscription in SQL Server 2014?

I have a report with two Date parameters "StartDate" and "EndDate."
I want to create multiple subscriptions to the report covering different time periods like previous calendar month, previous week, previous weekend, etc.
The most straightforward way that I can think of doing this is would be if the StartDate and EndDate parameters could be set to different expressions for each subscription. However I can't seem to get expressions to work at all from the subscription page. Is this possible?
The way I have handled this type of situation was to add a new parameter to the report that would allow you choose a report period to run for. This value would in turn be used to determine what dates to use for start date and end date.
The following steps outline how to do this.
Add a new parameter to the report named ReportPeriod.
Add the following Label(Value) pairs to the Available Values (Specified values) list.
Daily (D)
Weekly (W)
Monthly (M)
Make one of these the default, which doesn’t matter.
Move this new parameter up in the parameters list so that is above(before) the StartDate and EndDate parameters. They will derive their values based the chosen ReportPeriod, so it must come before them.
Set the default value expression for the StartDate parameter to this:
=Switch(Parameters!ReportPeriod.Value = "D", Today.AddDays(-1),
Parameters!ReportPeriod.Value = "W", DateAdd(DateInterval.WeekOfYear, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)-1), Today)),
Parameters!ReportPeriod.Value = "M", DateAdd(DateInterval.Month, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)-1), Today)))
Set the default value expression for the EndDate parameter to this:
=Switch(Parameters!ReportPeriod.Value = "D", Today,
Parameters!ReportPeriod.Value = "W", DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)), Today),
Parameters!ReportPeriod.Value = "M", DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)), Today))
You need to know that changing the ReportPeriod when running the report by hand will not update the StartDate and EndDate parameters right in front of you eyes. However, changing the default ReportPeriod will affect the values. More importantly, what ReportPeriod you choose when creating a report subscription will also affect the date values. Therefore, creating report subscriptions for this report, one for each ReportPeriod, will give you the results you desire.
Feel free to add more ReportPeriod available values, like Quarterly, or Annually, and adjust the expressions as needed.
Hope this helps you.
You can write expressions in SSRS design environment to set a default value for the date. The same will reflect in its subscriptions as "Report Default Value".
Custom -configure the date feature using "Override Report Default" is not available even in Data-driven subscriptions in SSRS up to 2012. Users can only select a fixed date.
Maybe this article helps:
https://www.sqlservercentral.com/Forums/1104266/Creating-a-dynamic-date-parameter-in-a-SQL-Reporting-Services-2005-subscription

Crystal Reports Date parameter date range issue

Using Crystal Reports version 8. Trying to restrict data retrieved based on date range provided by the user.
Here is the formula I am trying to use in the Select Expert:
{Query.current0} <> 0.00 and
{Query.status} in ["PIF", "SIF"] and
{Query.closed} >= DateTime ({?Start}, Time (00,00,00)) and
{Query.closed} <= DateTime ({?End}, Time (23,59,59))
When I click the error checking button, CR gives the error "A date-time is required here" and puts the cursor at the end of the second line after the "and".
I have confirmed both {?Start} and {?End} are Date parameters and they do have data in them. {Query.closed} is a datetime in the original database, and if I remove the {Query.closed} date restrictions, the report runs fine (it just pulls all the data in the database!).
Oddly enough, I have another Crystal Report that runs just fine using this formula in the Select Expert:
{Collect2000Log.LogWhen} >= DateTime ({?FromDate}, Time (00,00,00)) and
{Collect2000Log.LogWhen} <= DateTime ({?ToDate}, Time (23,59,59))
In both reports, the parameters involved are Date parameters, and both {Collect2000Log.LogWhen} and {Query.closed} are datetime fields. One major difference is the PIF/SIF report (the one with the errors) is built on a saved Crystal SQL Query and the one without errors was not.
Can anyone help me spot what I am missing?
After further exploration, I'm not sure what the actual issue was, however I re-created the report WITHOUT the use of Crystal SQL Queries and it is now pulling data just fine. Would appreciate knowing the details if anyone can explain, but for now mystery is solved!

Resources