Dear Russ:
Not very simply, but not too bad.
Let's create a table AnnualRange:
2005 1/1/2005 12/31/2005
2006 1/1/2006 12/31/2006
Put more years than just these in the table.
Is the "ship date" always less than the "receive date". That's the way I
understand this part.
A complete solution would also take usage out on 3/13/2002 and returning
3/13/2006 to have 5 parts:
3/13/2002 to 12/31/2002
1/1/2003 to 12/31/2003
1/1/2004 to 12/31/2004
1/1/2005 to 12/31/2005
1/1/2006 to 3/13/2006
I start with a cross product of the two tables, then eliminate those rows
not appropriate.
SELECT A.CYear, A.BeginDate, A.EndDate, B.ShipOut, B.ReturnIn
FROM AnnualRange A, EquipUtil B
The above reveals the tables I created to test this:
EquipUtil
ShipOut date/time
ReturnIn date/time
The AnnualRange table is as shown above.
The finished query:
SELECT A.CYear, A.BeginDate, A.EndDate, B.ShipOut, B.ReturnIn,
IIf(A.BeginDate < B.ShipOut, B.ShipOut, A.BeginDate) AS BeginMe,
IIf(A.EndDate > B.ReturnIn, B.ReturnIn, A.EndDate) AS EndMe
FROM AnnualRange A, EquipUtil B
WHERE A.BeginDate <= B.ReturnIn
AND A.EndDate >= B.ShipOut
You will need to adapt this to your table and column names.
Here's the test data and results:
AnnualRange CYear BeginDate EndDate
2000 1/1/2000 12/31/2000
2001 1/1/2001 12/31/2001
2002 1/1/2002 12/31/2002
2003 1/1/2003 12/31/2003
2004 1/1/2004 12/31/2004
2005 1/1/2005 12/31/2005
2006 1/1/2006 12/31/2006
EquipUtil ShipOut ReturnIn
3/13/2001 5/15/2005
MQry CYear BeginDate EndDate ShipOut ReturnIn BeginMe EndMe
2001 1/1/2001 12/31/2001 3/13/2001 5/15/2005 3/13/2001 12/31/2001
2002 1/1/2002 12/31/2002 3/13/2001 5/15/2005 1/1/2002 12/31/2002
2003 1/1/2003 12/31/2003 3/13/2001 5/15/2005 1/1/2003 12/31/2003
2004 1/1/2004 12/31/2004 3/13/2001 5/15/2005 1/1/2004 12/31/2004
2005 1/1/2005 12/31/2005 3/13/2001 5/15/2005 1/1/2005 5/15/2005
The equipment removed 3/13/2001 and returned 5/15/2005 returns 5 rows, the
first and last being for partial years.
I believe this is what you want. If you have trouble adjusting this to your
data, please fill in what that data is so I can make the adjustments.
Tom Ellison
Equipment Utilization
Ok, I need to figure out equipment utilization, the table I have is the
[quoted text clipped - 3 lines]
you split it per year 6 months in 2005 and 6 months in 2006?
Any help would be greatly appreciated.