事实:
我使用Access 2013,但它也必须在Access 2007中运行。
我有以下3个表:
命令:
Id DateFrom DateTo
1 2014-12-01 2015-03-01
2 2014-01-02 2015-03-01
3 2015-01-03 2015-03-01
库存:
Id Label Amount
1 Product1 20
2 Product2 10
待办事项:
Id OrderId StockId Amount
1 1 1 10
2 2 1 5
3 2 2 5
4 3 2 5
用户输入:
问题:
是否可以为日期为X到Y的子查询创建“临时”表?在用户输入中,如下所示:
dates
2015-01-01
2015-01-02
2015-01-03
我想得到以下结果:
Date StockLabel AmountInUse AmountAvailable
2015-01-01 Product1 10 10
2015-01-01 Product2 0 10
2015-01-02 Product1 15 5
2015-01-02 Product2 5 5
2015-01-03 Product1 15 5
2015-01-03 Product2 10 0
如果甚至可以在不使用VBA的Access中进行查询,查询的外观将如何?
是的。创建这样的查询:
SELECT DISTINCT
[Tens]+[Ones] AS Factor,
10*Abs([Deca].[id] Mod 10) AS Tens,
Abs([Uno].[id] Mod 10) AS Ones
FROM
msysobjects AS Uno,
msysobjects AS Deca;
将其另存为qdyFactor。然后创建此查询:
SELECT DISTINCT
DateAdd("d",[Factor],[DateFrom]) AS Dates
FROM
qdyFactor
WHERE
qdyFactor.Factor Between 0 And DateDiff("d",[DateFrom],[DateTo]);
这将创建日期列表。最后,使用它来过滤和汇总其他表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句