2009-05-23 67 views
1

有誰有如何加入3個表,我有以下語句的例子,但我得到一個缺少(語法錯誤「操作錯誤」)MS-訪問:加入3個表

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

發現問題,因爲它是一個訪問數據庫,fisrt from語句和INNER JOIN需要在括號中,如下所示。

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) 
0

如果您刪除WHERE子句,是否執行查詢?立即跳出來的唯一的事情是你的日期不一定會成爲OleDB提供者喜歡的格式。

我的猜測是,你需要封裝你的日期,如'1-Jan-2009'或類似的東西。

+0

它必須是與以下 – Domitius 2009-05-23 17:23:19

0

您的加入看起來不錯,但我認爲您的問題可能是您將'TaskNumber'與'aFromDate'比較的位置;數字和日期在SQL中是不同的類型,並且會導致嘗試比較它們的問題。

+0

的加盟,請參閱響應Ø對不起,既表字段和aFromDate變量是數字字段存儲日期爲數字這種格式20091101或20100225. – Domitius 2009-05-23 17:22:10