sqlcsvms-accessjet

'Syntax error in FROM clause' or 'Syntax error in JOIN operation' when joining two CSV files


I have two CSV files with baseball stats that I'm trying to join as follows,

SELECT 
    Master.playerID, Batting.RBI 
FROM 
    ([Master.csv] INNER JOIN [Batting.csv]) 
ON 
    (Master.playerID=Batting.playerID)

I've written a C# function to connect using Jet. I'm not having any trouble querying a single table (sample query SELECT COUNT(playerId) FROM [Master.csv] works fine), but for some reason it doesn't like the join.

Is it because the Master and Batting tables are unrecognized?

Relevant bits of my C# code attached,

string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
    FilePath + ";Extended Properties='text;HDR=Yes;FMT=Delimited;';";
OleDbConnection conn = new OleDbConnection(constr);
OleDbCommand command = new OleDbCommand(SQLStatement, conn);
conn.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
sda.Fill(dt);
sda.Dispose();
command.Dispose();
conn.Dispose();

The exception is thrown at the sda.Fill(dt) line and SQLStatement is simply the query string passed to the function as a string.


Solution

  • You add:

    SELECT m.playerID, b.RBI 
    FROM [Master.csv] as m INNER JOIN
         [Batting.csv] as b
         ON m.playerID = b.playerID;
    

    You may need a more advanced syntax to get at the files, but this fixes syntax errors.