I am new to SQL and need help with some complicated transactions. Using an Access DB and writing the code in VB6, I am creating a Racing Stats Program. The current 2 queries that I am trying to figure out gather driver stats for a selected track or track type. The tables involved and contents are:
Results - DriverID, EventID, Points
Drivers - DriverID, DriverFullName
Events - EventID, TrackID
Tracks - TrackID, TrackTypeID
TrackType - TrackTypeID, TrackID
In the first query I want to select all of the results per driver for the selected TrackID. The Results table does not contain the TrackID. It is located in the Events table which is reference by the EventID in the Results. My current code follows (which errors out): FYI - I have working queries that are similar to below but most of the data is contained in the Results table.
strSQL = "SELECT Drivers.DriverFullName, SUM(Results.ResultPoints), "
strSQL = strSQL & "AVG(Results.ResultPoints), AVG(Results.ResultStart), "
strSQL = strSQL & "AVG(Results.ResultFinish), SUM(ResultLapsComp), "
strSQL = strSQL & "SUM(ResultWinnings), SUM(ResultAdjustment) "
strSQL = strSQL & "FROM Results, Drivers "
strSQL = strSQL & "WHERE Results.DriverID = Drivers.DriverID AND "
strSQL = strSQL & "Year(Results.ResultDate) > " & CStr(cmbYear) & " AND "
strSQL = strSQL & "Events.TrackID = " & CStr(iTrackID) & " "
strSQL = strSQL & "GROUP BY Drivers.DriverFullName"
I've tried a couple of different approaches but I always error out. The code above produces "No value given for one or more required arguments". Another error concerned a non reference aggregate (I think).
The second query is similar to the above but it goes another step deeper. This time I want the same information but this is based on track type which adds another table into the equation. The query would be the same but now I need all of the results where all of the Tracks with the same TrackTypeID (which is referenced in the Tracks table) is the same as the TrackID of the selected track.
Whew! I know this is a lot of information and a lot to ask for. I've been working on this database and program off and on for 4 years and I'm getting closer to having something that works. Any help would be greatly appreciated.
LOL!! Once I get past this hurdle it's on to the next one which is calculating averages at intervals (Last 3, 4, 6 8, etc..) and then perfoming calcualtions on those results.
Results - DriverID, EventID, Points
Drivers - DriverID, DriverFullName
Events - EventID, TrackID
Tracks - TrackID, TrackTypeID
TrackType - TrackTypeID, TrackID
In the first query I want to select all of the results per driver for the selected TrackID. The Results table does not contain the TrackID. It is located in the Events table which is reference by the EventID in the Results. My current code follows (which errors out): FYI - I have working queries that are similar to below but most of the data is contained in the Results table.
strSQL = "SELECT Drivers.DriverFullName, SUM(Results.ResultPoints), "
strSQL = strSQL & "AVG(Results.ResultPoints), AVG(Results.ResultStart), "
strSQL = strSQL & "AVG(Results.ResultFinish), SUM(ResultLapsComp), "
strSQL = strSQL & "SUM(ResultWinnings), SUM(ResultAdjustment) "
strSQL = strSQL & "FROM Results, Drivers "
strSQL = strSQL & "WHERE Results.DriverID = Drivers.DriverID AND "
strSQL = strSQL & "Year(Results.ResultDate) > " & CStr(cmbYear) & " AND "
strSQL = strSQL & "Events.TrackID = " & CStr(iTrackID) & " "
strSQL = strSQL & "GROUP BY Drivers.DriverFullName"
I've tried a couple of different approaches but I always error out. The code above produces "No value given for one or more required arguments". Another error concerned a non reference aggregate (I think).
The second query is similar to the above but it goes another step deeper. This time I want the same information but this is based on track type which adds another table into the equation. The query would be the same but now I need all of the results where all of the Tracks with the same TrackTypeID (which is referenced in the Tracks table) is the same as the TrackID of the selected track.
Whew! I know this is a lot of information and a lot to ask for. I've been working on this database and program off and on for 4 years and I'm getting closer to having something that works. Any help would be greatly appreciated.
LOL!! Once I get past this hurdle it's on to the next one which is calculating averages at intervals (Last 3, 4, 6 8, etc..) and then perfoming calcualtions on those results.