Pulling prior year data - ms-access

I am working on a query to pull all turnover in the past calendar year that is going to be used daily. Rather than going in and having to change the date each time I would just like to be able to run the query and have it automatically only pull the last 365 days worth of data. The code itself looks like:
SELECT O867IA_VJOBHST.SYS_EMP_ID_NR, O867IA_VJOBHST.REC_EFF_STT_DT, O867IA_VJOBHST.EMP_ACN_TYP_CD
FROM O867IA_VJOBHST
WHERE (((O867IA_VJOBHST.EMP_ACN_TYP_CD)="HIR"));
Where the REC_EFF_STT_DT is the date the ACN_TYP_CD occurred, in this case when they were HIR (Hired)
Any Ideas?

Access SQL provides Date() and DateAdd() functions. You can work out what you need from those functions in the Immediate window ...
? Date()
9/9/2013
? DateAdd("d", -365, Date())
9/9/2012
Then you can filter REC_EFF_STT_DT on the same date range in a query like this ...
SELECT o.SYS_EMP_ID_NR, o.REC_EFF_STT_DT, o.EMP_ACN_TYP_CD
FROM O867IA_VJOBHST AS o
WHERE
o.REC_EFF_STT_DT BETWEEN DateAdd('d', -365, Date()) AND Date();

Related

Week To Date Based Off Current Date

I am looking for an expression that will allow to me find the date of Monday of the week of my Date Field, to be used in a filter for a tablix.
Example, my date field today is 22/01/2019. I would like an expression that will return 21/01/2019. If the date was 26/01/2019, it should still return 21/01/2019.
For next week 31/01/2019 would return 28/01/2019.
Week starting Monday going to Sunday.
If its also possible for a similiar expression but to find the beginning of the month as well?
Is that possible?
Many thanks
To get the date of last Monday that occurred you can use something like
=Today.AddDays(1-WeekDay(Today(),FirstDayOfWeek.Monday))
and for the first of the month its just
=DateSerial(Year(Today()), Month(Today()), 1)
Both the above are based on the today() function, if you need them based on a date parameter, then the expression is a little different but your question stated "today".
monday of the week use the following expression:
DateAdd("d",DatePart(DateInterval.WeekDay,Fields!myDatefield.Value,0,0)+1,Fields!myDatefield.Value)
first day of the month use the following expression:
=DateAdd("d",-(Day(Fields!myDatefield.Value)-1), Fields!myDatefield.Value)

Greater than / Less than date/time table expression

I have the following expression in a MS-access table:
IIf([End Date/Time]>="12/8/2016 6:00:00",1,0)
12/08/2016 18:15:00 will return a '1', however
12/08/2016 14:23:29 returns a '0'
I'm assuming this is an issue with AM/PM. I tried putting '6:00:00 AM' in my expression but no change.
Also I would like to replace '12/8/2016' with 'yesterday' but date()-1 doesn't seem to be working.
EDIT: I figured out that the time needs to be '06:00:00'. That yield the correct dates. Still don't know how to get this automatically (ie yesterday at 06:00)
Thanks
Your issue is that you threat dates as strings. Use date always, no exceptions.
Further, if your field is not a date value, you must convert it.
Thus, this will work:
IIf(DateValue([End Date/Time]) >= #2016/12/8 6:00:00#, 1, 0)
and this:
IIf(DateValue([End Date/Time]) >= Date() - 1, 1, 0)
and this:
IIf(DateValue([End Date/Time]) >= DateAdd("d", -1, #2016/12/8 6:00:00#), 1, 0)
2 things. First, I believe you need to convert your string to a datetime. I think think you're getting wonky results because it's trying to compare them as a different format. Like a strings or numbers. To format as a date time you use a format fucntion:
Format("12/8/2016 6:00:00AM", "mm/dd/yyyy hh:nn:ss am/pm")
Second, to add a date you need the DateAdd function.
DATEADD('d',-1,"12/8/2016 6:00:00AM")
'd' defines the -1 as a 'day' being added.
So, putting it all together:
DATEADD("d",-1,Format("12/8/2016 6:00:00AM", "mm/dd/yyyy hh:nn:ss am/pm"))
And finally, if you want the want the rolling yesterday, and not perpetually 12/7/2016 (since you would just use that date if it was the case), you need to get today's date with this function:
Date()
So, throwing this into our mix we get:
DATEADD("d",-1,Format(DATE() & " 6:00:00AM", "mm/dd/yyyy hh:nn:ss am/pm"))

give fromdate with Todays Date and time should be 00.00.00 in ssrs reports

I want to pass datetime parameter in such format that it should display today date with time 00.00.00 and todate like today date with time 23.00.00 in ssrs reports.
Misunderstood before, you have to use AddHours, AddMinutes and AddSeconds in parameter's default expression:
=Today().AddHours(23).AddMinutes(59).AddSeconds(0)
UPDATE
You can hide time in following:
=CDate(Format(Today().AddHours(23).AddMinutes(59).AddSeconds(0), "MM/dd/yyyy"))
You can use Format() function to achieve your goal.
=Format(Now(),"dd-MM-yyyy 00:00:00")
=Format(Now(),"dd-MM-yyyy 23:00:00")

MS Access Expression

I have an Access database I have built from the ground up, I have some queries that I use and work queues. I am trying to narrow down the results of the queries. I have one part that is giving me issues due to how complex the data I am working with is. The one in question I have written the following expression.
Expr1: IIf([Daily Work]![Loan Type]="Renewal"," ",
IIf([Daily Work]![Boarding Date]=Date(),True,False))
This is an expression within a query I am looking to see if Loan Type is Renewal and the Boarding Date is the current date, if both those fields are Renewal and Date respectively then mark the record as true, if not then false. It isn't working for me. What can I can do to make this work?
I'm guessing you're just not getting the results you expect, versus getting an error.
In that case, I would suggest that [Boarding Date] = Date() is most likely the problem. If [Boarding Date] contains a time component, it won't equal Date(). I usually use a date format to compare dates -
i.e.
Format([Boarding Date], "dd mmm yyyy") = Format(Date(), "dd mmm yyyy").
The more explicit you are with dates, the better.

Past 5 week calculation in WEBI (BO 4.0)?

I am facing issue in calculating past 5 week data based on current date (excluding currrent week)
For e.g:
Suppose we are in 40th week of this year, I need to get the sum of all the transactions for the previous 5 weeks (39, 38, 37, 36 & 35).
Currently calculating based on the calendar day but as Calendar day is giving the granular level of data, inorder to increase the performance I need to use the calendar week (sample data like (2012/40).
Is there a way to do this?
I'd construct a flag field (either in the back-end or in the universe) using datediff (in SQL Server terms).
Failing that, you could construct a variable in Web Intelligence using the Week function.
Pseudo-code but something like:
=IF(Transaction_Date < Week(CurrentDate()) AND Transaction_Date >= (Week(CurrentDate())-5); "TRUE"; "FALSE")