MS Access查询问题?

时间:2011-03-21 09:57:43

标签: sql ms-access subquery

我正在使用此查询:

SELECT D.Generic, D.Ww, D.Dd, D.Plan, c.TotalScan, D.Plan - c.TotalScan AS Balance
  FROM TableA D
       LEFT JOIN (
                  SELECT COUNT(a.Specific) AS TotalScan,
                         b.Generic, a.Dd,a.Ww  
                    FROM TableB a 
                         INNER JOIN TableC b 
                            ON a.Specific = b.Specific
                   GROUP 
                      BY b.Generic,a.Dd,a.Ww 
                   WHERE DATEDIFF(DAY, a.TransactionDate, GETDATE()) = 0
                 ) c
          ON c.Generic = D.Generic 
             AND D.Ww = c.Ww 
             AND c.Dd = D.Dd
 WHERE DATEDIFF(DAY, c.TransactionDate, GETDATE()) = 0;

过滤我的sqlserver数据库中插入的所有记录。

现在我很困难,如何才能进行访问。

1. DATEDIFF(Day, TransactionDate, GetDate()) = 0  -- Not Work on MS Access(Which Filter all Records inserted in current Date) 
2. Cant display TotalScan from subquery

示例输出日期:

TransactionDate
3/21/2011 7:26:24 AM
3/21/2011 7:26:24 AM
3/22/2011 7:26:24 AM --
3/22/2011 7:26:28 AM --
3/22/2011 7:26:30 AM --
3/22/2011 7:26:32 AM --
3/22/2011 7:26:35 AM --

如果我今天的日期是2011年3月22日,则会显示5条记录。

表示感谢

2 个答案:

答案 0 :(得分:4)

GetDate()是特定于SQL Server的,而Access则为Now()

Date中也存在DateDiff()函数,但间隔的参数不同:

DateDiff("d", TransactionDate, Now())

答案 1 :(得分:1)

相当于:

DATEDIFF(DAY, c.TransactionDate, GETDATE()) = 0

DATEDIFF("d", c.TransactionDate, Now()) = 0 

此致