views:

431

answers:

3

Hi,

Does anyone have a example of how to join 3 tables, I have the following statement but I'm getting a missing a (syntax error "operator 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

A: 

Does your query execute if you remove your WHERE clause? The only thing that immediately jumped out at me was your dates are not necessarily going to be in a format that the OleDB provider is going to like.

My guess is that you need to encapsulate your dates like '1-Jan-2009' or something similar.

Goyuix
it must be something to do with the join, see response below
Domitius
A: 

Your join looks okay, but I think your problem might be where you're comparing 'TaskNumber' to 'aFromDate'; numbers and dates are different types in SQL, and should cause a problem trying to compare them like this.

McWafflestix
o sorry, both the table field and the aFromDate variable is number fields storing dates as numbers in this format 20091101 or 20100225.
Domitius
i've tried it and it worked before I added the [Vegetables Descriptions] table
Domitius
If it worked before... it shouldn't be a problem with WHERE. Is the "Task" field in [Vegetables Descriptions] and [Date Schedules] same data type?
shahkalpesh
yes there both strings, if I do the INNER JOIN statements separately it's gets the selected data, but when i try to do both together as above I get a error.That's why I'm thinking there's somthing wrong with my systax.
Domitius
+1  A: 

Found the problem, because it's an access database the fisrt from statement and INNER JOIN needs to be in brackets 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)
Domitius