N
new2access
Suppose I have a table of data (one record per business day) that I wish to
run queries against. I wish to use the data from ANOTHER table to provide
input to the query Example: I have a table (call it "revenue") that contains
daily sales revenue. Each record in the table has the business date and
daily revenue for that date. I want to create a simple table of dates (call
it "searchdates") that will used as INPUT to queries against the revenue
database. (For the sake of this topic/question, I am simplifying the actual
set of data that I'm working with.)
What I'm trying to understand is this: Can I create a query such that I can
use the dates within the "searchdates" table as INPUT to a query agains the
"revenue" table ? Is it possible to use the concept of "For....next"
statements within a query ?
For example, I currently use a query to select the 20 days of revenue prior
to a specified date the user enters (usually an end of quarter date), and
allow the user to enter up to 4 dates, as follows:
SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 1]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 2]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 3]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 4]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 5]))
ORDER BY revenue.Date DESC
What I WANT to do is have this automated such that the query references a
table that has these "user entry" dates. Thus, I had hoped to use some
mechanism to cycle through each record in the "searchdates" table, use THAT
date as the [date X] inputs used above in my original query.....then cycle
through the "searchdates" file until no more records are in the "searchdates"
table.
I had seem some examples of using "for...next" loops within Access, but
wasn't sure whether I could use them here. OR, any other solution to allow
me to generate a query using another table as input......
Please help!!
run queries against. I wish to use the data from ANOTHER table to provide
input to the query Example: I have a table (call it "revenue") that contains
daily sales revenue. Each record in the table has the business date and
daily revenue for that date. I want to create a simple table of dates (call
it "searchdates") that will used as INPUT to queries against the revenue
database. (For the sake of this topic/question, I am simplifying the actual
set of data that I'm working with.)
What I'm trying to understand is this: Can I create a query such that I can
use the dates within the "searchdates" table as INPUT to a query agains the
"revenue" table ? Is it possible to use the concept of "For....next"
statements within a query ?
For example, I currently use a query to select the 20 days of revenue prior
to a specified date the user enters (usually an end of quarter date), and
allow the user to enter up to 4 dates, as follows:
SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 1]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 2]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 3]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 4]))
ORDER BY revenue.Date DESC
UNION SELECT TOP 25 revenue.*
FROM revenue
WHERE (((revenue.Date)<=[date 5]))
ORDER BY revenue.Date DESC
What I WANT to do is have this automated such that the query references a
table that has these "user entry" dates. Thus, I had hoped to use some
mechanism to cycle through each record in the "searchdates" table, use THAT
date as the [date X] inputs used above in my original query.....then cycle
through the "searchdates" file until no more records are in the "searchdates"
table.
I had seem some examples of using "for...next" loops within Access, but
wasn't sure whether I could use them here. OR, any other solution to allow
me to generate a query using another table as input......
Please help!!