Re: This should be simple but I don't know how!
- From: Alastair MacFarlane <AlastairMacFarlane@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 07:50:02 -0700
Thanks again Marshall.
I have altered the query above to suit my situation and it works perfectly.
I never knew that there were SQL queries (other than Union) that you could
type in and not see the result in the designer. I quess SQL Server View
designer is much better!
Thanks again.
Alastair
"Marshall Barton" wrote:
Alastair MacFarlane wrote:.
I have to tables with the schema below (see end of e-mail). I would like to
create a query that has an output like the following:
ID SaleDate Period
1 05/04/2006 1
2 05/05/2006 2
3 08/06/2006 3
What I am not sure about is how to calculate this without either code or a
DLookup. This would be very slow when I am looking at many millions of
records. I have a known date value in table 1 and I want to return the period
for that particular date in table 2 when I only have a date range as a guide.
Thanks again for your help.
Alastair MacFarlane
Table 1
ID SaleDate
1 05/04/2006
2 05/05/2006
3 08/06/2006
Table 2
ID Year Period StartDate EndDate
27 2006/07 1 01/04/2006 28/04/2006
28 2006/07 2 29/04/2006 26/05/2006
29 2006/07 3 27/05/2006 23/06/2006
I think this can do that:
SELECT table1.ID, table1.SaleDate, table2.Period
FROM table1 INNER JOIN table2
ON table1.SaleDate >= table2.StartDate
And table1.SaleDate <= table2.EndDate
Note that you can not specify this kind of join in the query
design window, so you will have to use the query's SQL view.
--
Marsh
MVP [MS Access]
- Follow-Ups:
- Re: This should be simple but I don't know how!
- From: Marshall Barton
- Re: This should be simple but I don't know how!
- References:
- Re: This should be simple but I don't know how!
- From: Marshall Barton
- Re: This should be simple but I don't know how!
- Prev by Date: Query on SQL Server 2000 Linked Table Doesnt Provide Correct Results
- Next by Date: Re: Query on SQL Server 2000 Linked Table Doesnt Provide Correct Results
- Previous by thread: Re: This should be simple but I don't know how!
- Next by thread: Re: This should be simple but I don't know how!
- Index(es):
Relevant Pages
|