Cartesian Query

J

Jeff

OK..I have been working on this query without much
success, I hope that someone can help me with this one.
I am sure that I need to use a Cartesion query but I am
having trouble making it work.
I need a query That shows a line for every date that
corresponds with the checked boxes in the table entry.

Example:
These are the "Meeting Table" fields:
EmployeeID, StartDate, EndDate, S,M,T,W,TH,F,SA (the last
7 are check boxes)


Table entries:
John Smith 10-1-03, 10-10-03, M,W,F (checked Boxes)
Jane Doe 10-1-03, 10-10-03, T,TH (checked Boxes)

Query Result:
John Smith 10-1-03
John Smith 10-3-03
John Smith 10-6-03
John Smith 10-8-03
John Smith 10-10-03
Jane Doe 10-2-03
Jane Doe 10-7-03
Jane Doe 10-9-03
 
J

John Spencer (MVP)

OUCH! The non-normalized check box set up for days of the week is going to make
this difficult. I might try something like the following SQL.

SELECT EmployeeID, DateAdd("d",NumTable.Num,StartDate) As CalcDate
FROM MeetingTable, NumTable
WHERE NumTable.Num <= DateDiff("d",StartDate,EndDate) AND
((WeekDay(DateAdd("d",NumTable.Num,StartDate)) = 1 AND S = True) OR
(WeekDay(DateAdd("d",NumTable.Num,StartDate)) = 2 AND M = True) OR
.... ) OR
(WeekDay(DateAdd("d",NumTable.Num,StartDate)) = 7 AND S = True))


NumTable would be a table with just the one field that holds one-up numbers.
From 1 to the highest number you would need (max number of days between Start
date and End Date plus 1)

This will probably be VERY slow.

You could also try using a union query to get the data normalized

SELECT EmployeeID, StartDate, EndDate, IIF(S = True, 1)
UNION ALL
SELECT EmployeeID, StartDate, EndDate, IIF(M = True, 2)
UNION ALL
....
SELECT EmployeeId, StartDate, EndDate, IIF(SA = True,7)

Then use that

SELECT EmployeeID, DateAdd("d",NumTable.Num,StartDate) As CalcDate
FROM UnionQuery, NumTable
WHERE NumTable.Num <= DateDiff("d",StartDate,EndDate)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Cartesain Query 7
Continuous Dates 5
Date Calculation.,. 3
Combine 2 tables for a report 2
Group By Query Problem 4
Select Max 1
joining results 3
Who's due for a shot? 2

Top