Ms-Access: join 3 tables

Does anyone have an example on how to join 3 tables, I have the following statement, but I get a missing one (syntax error "statement error")

da = New OleDbDataAdapter("SELECT [S].[Scheduled Vege], [V].[Description], 
        [DS].[Task], [DS].[Task Date], [DS].[Completed] FROM [Scheduled] AS S 
        INNER JOIN [Date Schedules] AS DS ON [S].[SchedID] = [DS].[SchedID] 
        INNER JOIN [Vegetables Descriptions] AS V ON [V].[Task] = [DS].[Task] 
        WHERE [DS].[TaskNumber] >= " & aFromDate & " AND [DS].[TaskNumber] <= " & aToDate & " 
        AND [DS].[Completed] = '" & aCompleted & "' ", conn)

      

thanks

+1


a source to share


3 answers


An issue has been encountered because it is an access database that must be in parentheses from the fisrt statement and the INNER JOIN as shown below.



da = New OleDbDataAdapter("SELECT [S].[Scheduled Vege], [V].[Description], 
[DS].[Task], [DS].[Task Date], [DS].[Completed] FROM ([Scheduled] AS S 
INNER JOIN [Date Schedules] AS DS ON [S].[SchedID] = [DS].[SchedID]) 
INNER JOIN [Vegetables Descriptions] AS V ON [V].[Task] = [DS].[Task] 
WHERE [DS].[TaskNumber] >= " & aFromDate & " AND [DS].[TaskNumber] <= " & aToDate & " 
AND [DS].[Completed] = '" & aCompleted & "' ", conn)

      

+4


a source


Is your query fulfilled if you remove the WHERE clause? The only thing that immediately jumped out to me was that your dates won't necessarily be in a format that OleDB would like.



I am assuming you need to encapsulate your dates, like "1-Jan-2009" or something similar.

0


a source


Your connection looks ok, but I think your problem might be that you are comparing " TaskNumber

" with " aFromDate

"; numbers and dates are different types in SQL and should cause a problem trying to compare them like this.

0


a source







All Articles