此查询
SELECT P2.ID, P2.Storenum, [Periods_2013-2014].[PeriodDate] AS [OpenFromDate],
P2.[Open From Day], P2.[Open From Time], P2.[Open To Day],
P2.[Open To Time]
FROM [Periods_2013-2014]
INNER JOIN [tblOpenCloseTimes] AS P2 ON [Periods_2013-2014].[Day]=P2.[Open From Day]
WHERE ((([Periods_2013-2014].Day)=P2.[Open From Day]
AND P2.Storenum ="43010605"
AND [Periods_2013-2014].Period = "4"))
导致“输入参数值”,Query1.PeriodDate
作为请求的参数,而如果我只是从第一行删除“AS [OpenFromDate]
”,则查询运行完美。如果我将[Periods_2013-2014]
表别名为P1,它也会这样做。这不会是一个问题,除了我需要堆叠查询以获取PeriodDate
字段两次。我究竟做错了什么?
更新:此查询
SELECT T2.Storenum, T2.[PeriodDate] AS [Open From Date], T2.[Open From Day],
T2.[Open From Time], T1.[PeriodDate] AS [Open To Date], T2.[Open To Day],
T2.[Open To Time]
FROM [Periods_2013-2014] AS T1,
(SELECT P2.Storenum, P1.[PeriodDate], P2.[Open From Day], P2.[Open From Time],
P2.[Open To Day], P2.[Open To Time]
FROM [Periods_2013-2014] AS P1 INNER JOIN tblOpenCloseTimes AS P2
ON P1.[Day]=P2.[Open From Day]
WHERE (((P1.Day)=P2.[Open From Day]
AND P2.Storenum ="43010605"
AND P1.Period = "4"))
ORDER BY P1.[PeriodDate]) AS T2
WHERE T1.[Day]=T2.[Open To Day]
AND T1.[PeriodDate]>=T2.[PeriodDate]
AND T1.[PeriodDate] - T2.[PeriodDate] <7
ORDER BY P1.[PeriodDate];
现在我已经从Property表中删除了Order By子句。
答案 0 :(得分:2)
Access不允许您在查询中使用字段别名。所以,我想问题出在你的Where
条款中。
尝试删除名称:P2
并使用完整的表名,以便您的语句如下所示:
SELECT [tblOpenCloseTimes].ID, [tblOpenCloseTimes].Storenum, [Periods_2013-2014].[PeriodDate] AS [OpenFromDate],
[tblOpenCloseTimes].[Open From Day], [tblOpenCloseTimes].[Open From Time], [tblOpenCloseTimes].[Open To Day],
[tblOpenCloseTimes].[Open To Time]
FROM [Periods_2013-2014]
INNER JOIN [tblOpenCloseTimes] ON [Periods_2013-2014].[Day]=[tblOpenCloseTimes].[Open From Day]
WHERE ((([Periods_2013-2014].Day)=[tblOpenCloseTimes].[Open From Day]
AND [tblOpenCloseTimes].Storenum ="43010605"
AND [Periods_2013-2014].Period = "4"))
我想知道为什么你为其中一个表使用别名而不是其他表。为列名使用别名很好。但是,这些别名不应该在Where子句中使用。
此外,您可以参考以下链接了解更多详情: