创建一个查询,以分析完成的好预测后需要在整个工厂中生产什么的查询。引入了每月需求,但试图找出如何轻松选择要查看的月份,因为它们是单独的列。
下面的SQL是我目前拥有的,我想从用户输入中对变量进行DIM选择以加粗的数字(月)。例如用户输入“ 4”,它将变为[MPS客户预测]![4]。感谢您的提前帮助。
SELECT [MPS Customer Forecast]![Part] AS [Finished Good]
, [MPSCustomer Forecast].Part
, ***[MPS Customer Forecast]![3]*** AS [MonthDemand]
, BOMs.[Component No]
, BOMs.[Component Name]
, BOMs.[BOMQuantity]
, ([BOMs]![BOM Quantity][MPS Customer Forecast]![3]***) AS [Comp Month Dem]
, [Active Routings - Primary].[Approved WorkcenterRates]
,[MPS Customer Forecast]![3][BOMs]![BOM Quantity]/[Active
Routings - Primary]![Approved Workcenter Rates] AS [Needed Hours]
,[Active Routings - Primary].[Workcenter Code]
答案 0 :(得分:0)
这是不可能的。您无法将参数传递给查询来决定要返回的列。
如果您无法访问用于计算这12个月的值的基础记录,那么我会看到两次实现您想要的机会:
1。使用UNION查询
不是查询表[MPS Customer Forecast]
,而是查询定义为UNION查询([MPS Customer Forecast UNION]
)的查询(如需要,添加更多字段):
SELECT 1 AS [Month], [1] AS [MonthDemand], [Part] FROM [MPS Customer Forecast]
UNION ALL
SELECT 2 AS [Month], [2] AS [MonthDemand], [Part] FROM [MPS Customer Forecast]
UNION ALL
...
UNION ALL
SELECT 12 AS [Month], [12] AS [MonthDemand], [Part] FROM [MPS Customer Forecast]
主查询可能看起来像这样(您忘记了MonthDemand
和BOMQuantity
之间的算术运算符,我也是):
PARAMETERS MonthParameter Short;
SELECT [MPS Customer Forecast UNION]![Part] AS [Finished Good]
, [MPS Customer Forecast UNION].Part
, [MPS Customer Forecast UNION].[MonthDemand]
, BOMs.[Component No]
, BOMs.[Component Name]
, BOMs.[BOMQuantity]
, ([BOMs]![BOM Quantity][MPS Customer Forecast UNION]![MonthDemand]) AS [Comp Month Dem]
, [Active Routings - Primary].[Approved WorkcenterRates]
,[MPS Customer Forecast UNION].[MonthDemand][BOMs]![BOM Quantity]/[Active
Routings - Primary]![Approved Workcenter Rates] AS [Needed Hours]
,[Active Routings - Primary].[Workcenter Code]
...
WHERE ((([MPS Customer Forecast UNION].[Month]) = [MonthParameter]))
2。使用Choose
函数选择12个值之一:
根据查询的参数选择值,而不是访问与月份相关的列:
PARAMETERS MonthParameter Short;
...
Choose([MonthParameter], [MPS Customer Forecast]![1], [MPS Customer Forecast]![2], [MPS Customer Forecast]![3], [MPS Customer Forecast]![4], [MPS Customer Forecast]![5], [MPS Customer Forecast]![6], [MPS Customer Forecast]![7], [MPS Customer Forecast]![8], [MPS Customer Forecast]![9], [MPS Customer Forecast]![10], [MPS Customer Forecast]![11], [MPS Customer Forecast]![12])
...