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.
Related
I am trying to produce a report that will pull a date already in a table somewhere and then show this date with 16 working days added on, below is the code I currently have;
SELECT d.CASENUM
,DATEADD (DW, 16, (d.ORDERDATE)) AS [PayDate]
FROM db.ORDERS AS d
WHERE d.CLIENT = 'STORE1'
The only issue I seem to having is that the DATEADD isn't adding 16 working days
27-01-2021 Is the last date in my table, so +16 working days should be 18-02-2021
but my results are giving me a date off 12-02-2021 and I can't figure out why..
I am using SQL Server Management Studio v18
Any help would be greatly appreciated.
I'm afraid what you'll have to do is create a new table for the Working Days. The issue is that different countries (and states) have different definition for Working Days.
So the table should look something like this
Date
State (or Locality)
Day of Week
Is Working Day
You can either use a running id for Working Days, alternatively use Windows Functions (RANK)Rank Windows Function
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)
I am using the following query (when connecting to SQL database in Direct Query mode) to get appointments for the previous 12 months:
Table.SelectRows(dbo_ReportAppointmentsView, each Date.IsInPreviousNMonths([Date], 12))
It was working perfectly fine and was generating SQL query with where clause like:
where convert(date, [_].[Date]) >= convert(datetime2, '2015-11-01 00:00:00') and convert(date, [_].[Date]) < convert(datetime2, '2016-11-01 00:00:00'))
The problem is that when current month changed (November -> December) it is still generating SQL query with exactly the same dates.
I expected the dates be '2015-12-01' and '2016-12-01' to display data for previous 12 months.
It helps to press "Refresh" button in Power BI desktop but it is clearly not a maintainable solution if I want the report to automatically display correct data.
Is it a bug or expected behavior?
This behaviour appeared to be a known issue.
The behavior you're observing when using Direct Query against SQL is a
known issue with the legacy Direct Query architecture. We will be
moving SQL Direct Query to a new architecture over the next few
months, but until then there's unfortunately no workaround besides
manually refreshing.
If by saying "Direct Query mode" you mean "Native Query", then it is not best practice and should be avoided.
Other than that, try replacing Date.IsInPreviousNMonths with something like
LocalDT = Date.LocalNow() //May be replaces with desired #date(2016, 11, 25) and likewise
ThisMonthStart = #date(Date.Year(LocalDT), Date.Month(LocalDT), 1),
CompareDate = Date.AddMonths(ThisMonthStart, -12),
Table.SelectRows(dbo_ReportAppointmentsView, each [Date] >= CompareDate)
and see if it generates another dates in query.
If you indeed using Native Query, then perhaps this is a bug linked to this mode.
All functions that check for a date(time) in a certain period relative to the system date(time), should be interpreted as ".... at last refresh".
In my opinion this is expected behavior, even when running is Direct Query mode: the latest data is accessed with the query definitions at last refresh.
My suggestion would be create a field in your SQL database with the current system date(time) (or just use it if it is already available) and select your data based on the value from that field.
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())
I have a Stored Procedure in SQL Server 2008. One of the values returned is:
SELECT DATEADD(mm, DATEDIFF(mm,0,e.Day), 0) AS [Month],
So I get values like: 2012-05-01 00:00:00.000
I want to display the month in the X axis for a chart report, obviously sorted chronologically. It would be great if I can display the month as "May-2012" or "2012 - May". Right now it displays the whole thing as 5/1/2012 12:00:00 AM and it is sorted alphabetically instead of by month.
When I check the Sorting it shows the field [Month] and order A to Z, so I assume it is not "seeing" it as a datetime value.
How do I get the sorting right?
How do I change the format to display the month as "May-2012" ?
Thanks in advance!
OK, work around:
I talked to my DBA, asked him to return a formatted field from the stored procedure, with values like "2012-05" and '2012-12' and sort by that field. Then I used that new field on the Report builder Chart, and remove all sorting.
Works for now, but still need to understand how to do it right for future reports.