L
ladybug via AccessMonster.com
I need criteria for a date field in my query. I want only the dates returned
that are older than 5 business days.
Thanks!
that are older than 5 business days.
Thanks!
ladybug said:I need criteria for a date field in my query. I want only the dates returned
that are older than 5 business days.
DateAdd("d", -7, Date())
KARL said:Here is one way. If you know subqueries then this can be done as a sub.
Create a table named CountNumber with integer field named CountNUM
containing numbers 0 (zero) through 99. Add this query in your query design
view and use criteria on your date field -------- <[Dates]
SELECT TOP 5 DateAdd("d",-[CountNUM],Date()) AS Dates
FROM CountNumber
WHERE (((Weekday(DateAdd("d",-[CountNUM],Date()))) Between 2 And 6))
ORDER BY DateAdd("d",-[CountNUM],Date()) DESC;
I need criteria for a date field in my query. I want only the dates returned
that are older than 5 business days.
Thanks!
KARL DEWEY said:Here is one way. If you know subqueries then this can be done as a sub.
Create a table named CountNumber with integer field named CountNUM
containing numbers 0 (zero) through 99. Add this query in your query design
view and use criteria on your date field -------- <[Dates]
SELECT TOP 5 DateAdd("d",-[CountNUM],Date()) AS Dates
FROM CountNumber
WHERE (((Weekday(DateAdd("d",-[CountNUM],Date()))) Between 2 And 6))
ORDER BY DateAdd("d",-[CountNUM],Date()) DESC;
--
KARL DEWEY
Build a little - Test a little
ladybug via AccessMonster.com said:I need criteria for a date field in my query. I want only the dates returned
that are older than 5 business days.
Thanks!
Marshall said:Sorry, but I can't do much of anything useful until you
provide a very detailed explanation of how your database
knows what a "business day" is. The least you must do is
define "business day" is very specific terms.[quoted text clipped - 13 lines]The code you gave is perfect except it does not remove weekends. Can you
help me with the function you were referring to? I know very little about
KARL said:After I posted I realized there needed to be one more query step. Use the
posted query in a second query --
SELECT Min([Dates-5_Bus_Days].Dates) AS MinOfDates
FROM [Dates-5_Bus_Days];
This results in the earlist date in the output. Use it in criteria
<[MinOfDates][quoted text clipped - 10 lines]Here is one way. If you know subqueries then this can be done as a sub.
Create a table named CountNumber with integer field named CountNUM
I do not have anything in the database that defines "business day." What I
mean by business day are days Monday through Friday (excluding holidays). So
if I run my query today, I only want entries with dates 4/23 and older. Does
that help?
Marshall said:Sorry, but I can't do much of anything useful until you
provide a very detailed explanation of how your database
knows what a "business day" is. The least you must do is
define "business day" is very specific terms.[quoted text clipped - 13 lines]The code you gave is perfect except it does not remove weekends. Can you
help me with the function you were referring to? I know very little aboutor a complex Function that can be used to calculate the
earliest date you want to see in the query's result.
ladybug via AccessMonster.com said:Ok, I am so sorry...I am just not following.
Here is the code for the query that I have now:
SELECT tbl_status_of_lif.number AS [Lifecycle #], tbl_status_of_lif.status_dt
AS [Status Date], tbl_status_of_lif.status AS Status, tbl_status_of_lif.
sub_by AS [Submitted by]
FROM tbl_status_of_lif
WHERE (((tbl_status_of_lif.status)<>"lc closed") AND ((tbl_status_of_lif.
status_id) In (SELECT Max(Status_ID) as MaxID
FROM tbl_status_of_lif INNER JOIN
(SELECT number, Max(Status_Dt) as LastDate
FROM tbl_status_of_lif
GROUP BY number) as Tmp
ON tbl_status_of_lif.number = Tmp.number
and tbl_status_of_lif.Status_dt = Tmp.LastDate
GROUP BY tbl_status_of_lif.number, tbl_status_of_lif.Status_dt)))
ORDER BY tbl_status_of_lif.status_dt DESC;
I built the table you told me to. Now where do I put what you told me? Do I
add it to this query or do I create a new query. Sorry that I am not getting
it, but I really do appreciate your help!
KARL said:After I posted I realized there needed to be one more query step. Use the
posted query in a second query --
SELECT Min([Dates-5_Bus_Days].Dates) AS MinOfDates
FROM [Dates-5_Bus_Days];
This results in the earlist date in the output. Use it in criteria
<[MinOfDates][quoted text clipped - 10 lines]Here is one way. If you know subqueries then this can be done as a sub.
Create a table named CountNumber with integer field named CountNUMThanks!
KARL DEWEY said:Name the first query Dates-5_Bus_Days
SELECT TOP 5 DateAdd("d",-[CountNUM],Date()) AS Dates
FROM CountNumber
WHERE (((Weekday(DateAdd("d",-[CountNUM],Date()))) Between 2 And 6))
ORDER BY DateAdd("d",-[CountNUM],Date()) DESC;
Name the second query Dates-5_Bus_Days-1
SELECT Min([Dates-5_Bus_Days].Dates) AS MinOfDates
FROM [Dates-5_Bus_Days];
Then here is your query edited --
SELECT tbl_status_of_lif.number AS [Lifecycle #],
tbl_status_of_lif.status_dt AS [Status Date], tbl_status_of_lif.status AS
Status, tbl_status_of_lif.sub_by AS [Submitted by]
FROM tbl_status_of_lif, [Dates-5_Bus_Days-1]
WHERE (((tbl_status_of_lif.status_dt)<[MinOfDates]) AND
((tbl_status_of_lif.status)<>"lc closed") AND ((tbl_status_of_lif.status_id)
In (SELECT Max(Status_ID) as MaxID
FROM tbl_status_of_lif INNER JOIN
(SELECT number, Max(Status_Dt) as LastDate
FROM tbl_status_of_lif
GROUP BY number) as Tmp ON tbl_status_of_lif.number = Tmp.number
and tbl_status_of_lif.Status_dt = Tmp.LastDate
GROUP BY tbl_status_of_lif.number, tbl_status_of_lif.Status_dt)))
ORDER BY tbl_status_of_lif.status_dt DESC;
--
KARL DEWEY
Build a little - Test a little
ladybug via AccessMonster.com said:Ok, I am so sorry...I am just not following.
Here is the code for the query that I have now:
SELECT tbl_status_of_lif.number AS [Lifecycle #], tbl_status_of_lif.status_dt
AS [Status Date], tbl_status_of_lif.status AS Status, tbl_status_of_lif.
sub_by AS [Submitted by]
FROM tbl_status_of_lif
WHERE (((tbl_status_of_lif.status)<>"lc closed") AND ((tbl_status_of_lif.
status_id) In (SELECT Max(Status_ID) as MaxID
FROM tbl_status_of_lif INNER JOIN
(SELECT number, Max(Status_Dt) as LastDate
FROM tbl_status_of_lif
GROUP BY number) as Tmp
ON tbl_status_of_lif.number = Tmp.number
and tbl_status_of_lif.Status_dt = Tmp.LastDate
GROUP BY tbl_status_of_lif.number, tbl_status_of_lif.Status_dt)))
ORDER BY tbl_status_of_lif.status_dt DESC;
I built the table you told me to. Now where do I put what you told me? Do I
add it to this query or do I create a new query. Sorry that I am not getting
it, but I really do appreciate your help!
KARL said:After I posted I realized there needed to be one more query step. Use the
posted query in a second query --
SELECT Min([Dates-5_Bus_Days].Dates) AS MinOfDates
FROM [Dates-5_Bus_Days];
This results in the earlist date in the output. Use it in criteria
<[MinOfDates]
Here is one way. If you know subqueries then this can be done as a sub.
Create a table named CountNumber with integer field named CountNUM
[quoted text clipped - 10 lines]
Thanks!
KARL said:If you want to omit holidays then build a table with DateTime field Holiday.
Use this as first query --
SELECT TOP 5 DateAdd("d",-[CountNUM],Date()) AS Dates
FROM CountNumber, Holiday
WHERE ((Weekday(DateAdd("d",-[CountNUM],Date()))) Between 2 And 6) AND
[quoted text clipped - 55 lines]Name the first query Dates-5_Bus_Days
SELECT TOP 5 DateAdd("d",-[CountNUM],Date()) AS Dates