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
Related
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.
Sorry guys - new to this - complete novice.
I am pulling data from a SQL Server from Excel using Microsoft Query.
I'm currently limiting fields to just invoices within a date range using:
=#10/1/2017# And <#10/31/2017#
My date format is:
2017-10-02 00:00:00.000
I run this report many times during the current month - so I need to change the string above when the new, current month, begins.
I'd love for someone to give me the command that will always pull the current month - regardless of the month - thus allowing me to not have to alter the condition when a new month begins.
Thank you in advance.
The question is not so clear but here is what you can try with:
To find today with date and time:
=NOW()
To find the beginning of the month:
=EOMONTH(A2,-1)+1
To find the end of the month:
=EOMONTH(A2,0)
Let me know if this is what you are expecting.
Using qlikview 8 personnel edition.
On my main tab i have a chart that concats year and period (year and month) from this I use it as a filter to select periods, this works fine except when trying to select multiple years and periods, it allows selection but say:
Select all from year 2013, and up to year 2014 month 09. It actually selects all from 2013 and 2014.
why would it be doing this?
Some details:
=Num#(If(Len(Year & Period)=5,Year & '0' & Period, Year & Period))
outputs "201301" etc
Like I said i can select whatever month upto a month i want withing a year. However doing the same over multiple years forces it to select all months.
Because the year & month columns are separate in your model, making the selection that you described actually DID select all of the months. You got them from 2013. It didn't care that you only hoped to limit to 1-9 for 2014.
If possible, move that concatenation to the load script where it can become its own field and then you should be good to go.
I have a report written in visual studio running on a SQL server 2005 DB.
I want it to automatically apply the day before's date
- start at 00:00:00 and end 23:59:59
From my pic the code I use is
=DateAdd(Dateinterval.day, -1, Now()) for the start date
and for end date I use
=Now()
These values get me a report for the last 24 hours but I want to get the report to run just for the 24 hours of the previous day. How would I do this?
I think you should be using Today() instead of Now().
Both will give today's date, but Today() will not include any time portion.
You should only use one date paramater being yesterday =DateAdd(DateInterval.Day, -1, Today()).
Then to use this your data should be truncated to the date only and filtered to equal this parameter getting yesterday only irrispective of the time.
I have a numeric field in my Oracle database that represents the number of days since Dec 28, 1800. However I am trying to select it (for another application) as the current date it represents. I'm not too familiar with Oracle commands (I'm used to SQL), so I was wondering if anyone could provide some assistance. Thanks.
ex: 77650 = Saturday, August 3, 2013
Firstly, get this out of the way, your life would be easier if you stored dates in a date data-type.
However, to answer your question to add days to a date in Oracle you can use the + operator.
Firstly though you have to have a date so I'll convert the 28th December 1800 into a date using to inbuilt to_date function then add the number. In your case you would want:
select to_date('1800/12/28','yyyy/mm/dd') + 77650 from dual
I've set up a little SQL Fiddle to demonstrate for you.