【问题标题】:MS Access Multiple table Inner join with where clauseMS Access 多表内连接与 where 子句
【发布时间】:2015-12-21 14:27:14
【问题描述】:

我尝试在 MS Access 数据库中内连接三个表,但出现以下错误:

“(缺少的运算符)”。

这是我的查询:

select DISTINCT
    Student.Student_Id,
    Student.Name,
    Student.Father_Name,
    Student.Dob
from (Student
    INNER JOIN Admissions
        ON Student.Student_Id = Admissions.Student_Id)
INNER JOIN Batches
    ON Admissions.Batch_Id = Batches.Batch_Id
where (Batches.Year = @p1
AND (Student.Student_Id LIKE @p2 + '%'))

【问题讨论】:

  • 如果此查询是在 Access 表的查询生成器中创建的,我看不到它有问题。表是 MS Access 还是链接的 SQL 表?是对SQL数据库的直通查询吗?

标签: ms-access-2010


【解决方案1】:

from 子句周围有一组多余的括号。只需删除它们就可以了:

SELECT     DISTINCT
           Student.Student_Id,
           Student.Name,
           Student.Father_Name,
           Student.Dob
FROM       Student
INNER JOIN Admissions
        ON Student.Student_Id = Admissions.Student_Id
INNER JOIN Batches
        ON Admissions.Batch_Id = Batches.Batch_Id
WHERE      (Batches.Year = @p1
            AND (Student.Student_Id LIKE @p2 + '%'))

【讨论】:

    【解决方案2】:

    在你的最后一行中,@p2% 两侧必须有'(单引号)

    表示

    AND (Student.Student_Id LIKE  '1%')
    

    所以让您的查询正确,如下所示

    select DISTINCT
        Student.Student_Id,
        Student.Name,
        Student.Father_Name,
        Student.Dob
    from (Student
        INNER JOIN Admissions
            ON Student.Student_Id = Admissions.Student_Id)
    INNER JOIN Batches
        ON Admissions.Batch_Id = Batches.Batch_Id
    where (Batches.Year = @p1
    AND (Student.Student_Id LIKE '' + cast(@p2 as varchar)  + '%'))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多