0

我正在尝试在 Access DB 上运行查询,我习惯于 SQL 查询,但这似乎并没有以同样的方式工作。这是我的查询:

OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "SELECT RecordID, TimeStamp, EmployeeName, AreaDescription       FROM LoginRecords r, Employees e, Areas a WHERE((e.EmployeeID = r.EmployeeID) && (a.AreaID =r.AreaID) && (TimeStamp > startDate AND < endDate)) ORDER BY TimeStamp;"

我似乎无法让它运行,但从技术上讲,从 SQL 的角度来看,这应该是一个很好的查询。这些表是 LoginRecords、Employees、Areas。如果有帮助,我可以加载表格。我感谢任何关于为什么这在 Access 中不起作用的反馈。startDate 和 endDate 是来自用户输入框的变量。

4

1 回答 1

1

试试这个,

这是SQL-92

SELECT      RecordID, 
            TimeStamp, 
            EmployeeName, 
            AreaDescription       
FROM        LoginRecords r
                INNER JOIN Employees e
                    ON e.EmployeeID = r.EmployeeID
                INNER JOIN Areas a 
                    ON a.AreaID = r.AreaID
WHERE   TimeStamp > startDate AND
        TimeStamp < endDate
ORDER BY TimeStamp;

使用SQL-92格式而不是SQL-89格式,因为SQL-89除了旧样式CROSS JOIN)如果处理不当很容易发生。

这是SQL-89

SELECT      RecordID, 
            TimeStamp, 
            EmployeeName, 
            AreaDescription       
FROM        LoginRecords r, Employees e, Areas a
WHERE   (e.EmployeeID = r.EmployeeID) AND
        (a.AreaID = r.AreaID) AND
        (TimeStamp > @startDate AND
         TimeStamp < @endDate)
ORDER BY TimeStamp;

MSACCESS:内连接,外连接(左和右)

于 2012-09-04T00:35:39.030 回答