I have a long SQL statement in VB6 that pulls data from a couple of MS Access tables to calculate some baseball statistics.
QUESTION:
How do I add another INNER JOIN to the SQL statement? I already have one INNER JOIN integrated already, but I can't seem to get the second one---I get syntax errors all the time so I'm not getting the punctuation etc correct.
My functioning statement that simply adds the blank columns and their field names is seen here:
SqlString = "SELECT (Master.nameFirst + '_' + Master.nameLast) AS Player, (Batting.yearID & Batting.teamID) AS Team, Fielding.POS AS POS, Batting.G, AB, R, H, [2B], [3B], HR, RBI, (Master.bats) AS BAT, BB, SO, Batting.SB, Batting.CS, ((H + BB + HBP) / (AB + BB + HBP + SF)) AS OBP, ('') AS vs_L, ('') AS vs_R, ((Fielding.PO + Fielding.A) / (Fielding.PO + Fielding.A + Fielding.E)) AS FPCT FROM (Batting INNER JOIN Master ON Batting.playerID = Master.playerID) INNER JOIN Fielding ON Batting.playerID = Fielding.playerID WHERE Fielding.A > 0 AND AB > 0 AND Batting.yearID = " & Text12.Text & " AND Batting.teamID = " & "'" & Text13.Text & "'" & " ORDER BY Batting.G DESC"
I'm trying to INNER JOIN two more fields from another table called 'BatSplits'. My functioning statement creates two blank columns called 'vs_R' and 'vs_L' [see above]. I have changed my statement to include the table these columns come from----here are the statements I've added:
(BatSplits.vs_LHP) AS vs_L, (BatSplits.vs_RHP) AS vs_R
Here's what I have so far.... it doesn't work because the INNER JOIN part is not integrated yet:
SqlString = "SELECT (Master.nameFirst + '_' + Master.nameLast) AS Player, (Batting.yearID & Batting.teamID) AS Team, Fielding.POS AS POS, Batting.G, AB, R, H, [2B], [3B], HR, RBI, (Master.bats) AS BAT, BB, SO, Batting.SB, Batting.CS, ((H + BB + HBP) / (AB + BB + HBP + SF)) AS OBP, (BatSplits.vs_LHP) AS vs_L, (BatSplits.vs_RHP) AS vs_R, ((Fielding.PO + Fielding.A) / (Fielding.PO + Fielding.A + Fielding.E)) AS FPCT FROM (Batting INNER JOIN Master ON Batting.playerID = Master.playerID) INNER JOIN Fielding ON Batting.playerID = Fielding.playerID WHERE Fielding.A > 0 AND AB > 0 AND Batting.yearID = " & Text12.Text & " AND Batting.teamID = " & "'" & Text13.Text & "'" & " ORDER BY Batting.G DESC"
Many thanks for any assistance....
I'm going to be doing a MS Access INSERT FIELD on one of the tables to solve the problem. I can reference both/either ID field once they're in the same table.
Be on the lookout for an MS Access INSERT FIELD question I'll be asking if you're interested. Many thanks