我不能让这个SQL工作,有人能发现它吗?

时间:2012-10-05 13:45:51

标签: sql database ms-access

SELECT 
    [Stock Conversion Items].SCID, 
    [Stock Conversion Items].[Result PC], 
    [Stock Conversion Items].[Quantity], 
    [Stock Conversion].[Date], 
    [products/stock].[Description] 
FROM 
    [Stock Conversion Items] 
INNER JOIN [Stock Conversion] 
    ON [Stock Conversion Items].SCID = [Stock Conversion].SCID 
INNER JOIN [products/stock] 
    ON [Stock Conversion Items].[Result PC] = [products/stock].[Product Code] 
ORDER BY [Stock Conversion Items].SCID;

这段代码非常自我解释,基本上我得到的语法操作符错误根本无法解决。

3 个答案:

答案 0 :(得分:3)

稍微重新格式化了查询,看起来像这样:

SELECT sci.SCID, sci.[Result PC], sci.Quantity, sci.Date, s.Description
FROM [Stock Conversion Items] sci
INNER JOIN [Stock Conversion] sc 
   ON sci.SCID = sc.SCID 
INNER JOIN [products/stock] s 
   ON sci.[Result PC] = s.[Product Code] 
ORDER BY sci.SCID;

该声明中唯一可能失败的是on子句。您确定两个SCID列的类型相同,还有[Result PC]和[Product Code]列?

答案 1 :(得分:0)

由于某种原因,Access似乎想在第一个连接周围放置括号。这似乎有效:

SELECT [Stock Conversion Items].SCID, [Stock Conversion Items].[Result PC], [Stock Conversion Items].Quantity, [Stock Conversion].Date, [products/stock].Description
FROM ([Stock Conversion] INNER JOIN [Stock Conversion Items] ON [Stock Conversion].SCID = [Stock Conversion Items].SCID) INNER JOIN [products/stock] ON [Stock Conversion Items].[Result PC] = [products/stock].[Product Code];

答案 2 :(得分:0)

        SELECT [Stock Conversion Items].SCID,
     [Stock Conversion Items].[Result PC],
     [Stock Conversion Items].Quantity,
     [products/stock].Description,
     [Stock Conversion].[SC Date],
     [Stock Conversion].[Created By]

     FROM [Stock Conversion Items]
      INNER JOIN ([products/stock] INNER JOIN [Stock Conversion]
        ON [products/stock].[Product Code] = [Stock Conversion].[Source PC])
        ON [Stock Conversion Items].SCID = [Stock Conversion].SCID;

所以这就是Access提出来解决我的问题,设法使事情有效,认为它可能是数据类型不匹配。谢谢Sweko。