I have a rather simple SQL statement, but I can't get it to work properly. I have four columns in the activities table "LoginID", "StartDateTime" , "StopDateTi me", and "ProjectID" . In a second table, Projects, I have "ProjectID" and "ProjectNam e". The goal of the SQL statement is to join the two ProjectID together, and get the difference in the stop and start time and any projects that are the same, sum or group them together. My SQL statement looks like this:
[code=mysql]SELECT datediff('n', [StartDateTime],[StopDateTime]) AS TotalDay, Projects.Projec tName
FROM Activity INNER JOIN Projects ON Activity.Projec tID = Projects.Projec tID
GROUP BY Projects.Projec tName, Activity.LoginI D, Projects.Projec tID, Activity.StartD ateTime, Activity.StopDa teTime
HAVING (Activity.Start DateTime Between #9/25/2008# AND #9/25/2008 8:13:29 AM# AND Activity.LoginI D=1)
ORDER BY Projects.Projec tName[/code]
Long, but straight forward. I've tried adding SUM around the datediff, but that doesn't work. In the activities table I have two entries that the SQL statement selects and the "ProjectID" are identical on both of them, but the project is I keep getting back both entries (the same two rows), with the correct time difference. What I expect to get back is one row with the values/times combined. Does anyone know how I can solve this problem with a single SQL statement, multiple SQL statements, or an operation on a dataset?
Thanks in advance,
Harry
[code=mysql]SELECT datediff('n', [StartDateTime],[StopDateTime]) AS TotalDay, Projects.Projec tName
FROM Activity INNER JOIN Projects ON Activity.Projec tID = Projects.Projec tID
GROUP BY Projects.Projec tName, Activity.LoginI D, Projects.Projec tID, Activity.StartD ateTime, Activity.StopDa teTime
HAVING (Activity.Start DateTime Between #9/25/2008# AND #9/25/2008 8:13:29 AM# AND Activity.LoginI D=1)
ORDER BY Projects.Projec tName[/code]
Long, but straight forward. I've tried adding SUM around the datediff, but that doesn't work. In the activities table I have two entries that the SQL statement selects and the "ProjectID" are identical on both of them, but the project is I keep getting back both entries (the same two rows), with the correct time difference. What I expect to get back is one row with the values/times combined. Does anyone know how I can solve this problem with a single SQL statement, multiple SQL statements, or an operation on a dataset?
Thanks in advance,
Harry
Comment