0

在我的项目中,我必须将我的数据库从 SQL Server 2005 更改为 MS Access。但是某些查询无法与 MS Access 一起正常工作。任何人都可以将以下查询从 sql 转换为 MS Access

SELECT l.id,
        REPLACE(SUBSTRING(CONVERT(VARCHAR(20), l.app_date, 13), 1, 11), ' ', '/') AS app_date,
        l.reason,
        REPLACE(SUBSTRING(CONVERT(VARCHAR(20), l.fromdate, 13), 1, 11), ' ', '/') AS fromdate,
        REPLACE(SUBSTRING(CONVERT(VARCHAR(20), l.todate, 13), 1, 11), ' ', '/') AS todate,
        lt.LeaveDesc,
        l.noofdays,
        e.Abbv_name,
        e1.Abbv_name AS Expr1,
        l.Typeofleave AS Leave_ID
FROM leave AS l
INNER JOIN LeaveTypes AS lt
        ON l.Typeofleave = lt.TypeofLeave
LEFT JOIN Employee AS e1
        ON l.HRby = e1.Emp_id
LEFT JOIN Employee AS e
        ON l.approveby = e.Emp_id
WHERE l.submitby = 2
        AND submit = 'Y'
        AND approved IS NULL

在上面的查询中,离开是我的数据库表。在此先感谢...

4

1 回答 1

1

FROM当您连接超过 2 个数据源时,Access 数据库引擎需要在子句中使用括号。在查询设计器的设计视图中构建您的联接。它将添加引擎要求的括号。在我的脑海中,我认为这个修改后的FROM条款可能会奏效:

FROM ((leave AS l
INNER JOIN LeaveTypes AS lt
        ON l.Typeofleave = lt.TypeofLeave)
LEFT JOIN Employee AS e1
        ON l.HRby = e1.Emp_id)
LEFT JOIN Employee AS e
        ON l.approveby = e.Emp_id

如果app_datefromdatetodate是日期/时间数据类型,则可以使用Format()表达式将日期值作为格式化字符串返回。

SELECT Format(app_date, 'dd/mon/yyyy hh:nn:ss')
于 2012-10-20T15:57:30.343 回答