2016-07-16 94 views
1

我試圖從不同的表中加入不同的數據類型。我認爲我的語法正確,但顯然我必須做錯了什麼。使用不同的數據類型連接兩個表MS Access

語法錯誤表示輸入表達式不匹配,所以我敢肯定我沒有正確地轉換數據類型

這是我加入

SELECT CLng([Inventory].ItemID) AS [Item#], 
Sum([Invoice].Quantity) AS [Order QTY] 
FROM [Invoice] INNER JOIN [Inventory] ON [Invoice].ItemID = CLng([Inventory].ItemID) 
WHERE ((([Invoice].OrderNumber) BETWEEN 1 And 23)) 
GROUP BY CLng([Inventory].ItemID); 
+0

它們是不同的數據類型? – scaisEdge

+0

@scaisEdge Inventory.ItemID是String和Invoice.ItemID是數字 –

+0

爲什麼不將Inventory.ItemID轉換爲LongInt? – Andre

回答

1

爲什麼在那裏裏面()?嘗試除去和轉換數爲str

SELECT CLng([Inventory].ItemID) AS [Item#], 
Sum([Invoice].Quantity) AS [Order QTY] 
FROM [Invoice] INNER JOIN [Inventory] ON Str ([Invoice].ItemID) = [Inventory].ItemID 
WHERE [Invoice].OrderNumber) BETWEEN 1 And 23 
GROUP BY CLng([Inventory].ItemID); 

SELECT CLng([Inventory].ItemID) AS [Item#], 
Sum([Invoice].Quantity) AS [Order QTY] 
FROM [Invoice] INNER JOIN [Inventory] ON CLng(Str ([Invoice].ItemID)) = CLng([Inventory].ItemID) 
WHERE [Invoice].OrderNumber) BETWEEN 1 And 23 
GROUP BY CLng([Inventory].ItemID); 
+0

仍然類型不匹配,即使我以前嘗試過。我習慣了由於訪問權限的額外括號,有時會在查詢中添加它們。 –

+0

比較ItemID字段時,可以使用CLng轉換其中一個,但不能使用其他轉換。你可以嘗試使用... JOIN [Inventory] ​​ON CLng([Invoice] .ItemID)= CLng([Inventory] ​​.ItemID) – x82

+0

@ x82我已經轉換了字符串中的數字和字符串([Inventory] ​​.ItemID)沒有與CLng – scaisEdge

相關問題