语法错误通过Microsoft Access

时间:2017-07-27 15:35:37

标签: sql ms-access

我正在尝试在“DATE”列上连接一个表(sheet1)3次。但每次我加入下一张桌子时,我都希望它在原始日期之前3,6和9个月的日期。

我在Microsoft SQL Server Management Studio上使用另一个类似的表尝试了此查询并且运行正常,但是当我在Microsoft Access中通过SQL运行查询时,我收到了SYNTAX ERROR(缺少运算符)。

任何帮助将不胜感激,谢谢!

Sheet1有2列,“Date”和“SA372 return”。

select 
   Sa.Date ,
   Sa.[SA372 returns], 
   (1+ Sa.[SA372 returns])*(1 + Sb.[SA372 returns])* (1+ Sc.[SA372 returns])*(1+ Sd.[SA372 returns]) as Compound 

from sheet1 Sa

left join  

sheet1 Sb on  Sb.Date = DATEADD(day,-1,dateadd(month,-3,DATEADD(day,1,Sa.Date)))

left join 

sheet1 Sc on  Sc.Date= DATEADD(day,-1,dateadd(month,-6,DATEADD(day,1,Sa.Date)))

left join 

sheet1 Sd on  Sd.Date= DATEADD(day,-1,dateadd(month,-9,DATEADD(day,1,Sa.Date)))

order by Sa.date asc

1 个答案:

答案 0 :(得分:1)

没有测试,我认为这就是你所追求的:

SELECT  
    Sa.Date
    , Sa.[SA372 returns]
    , (1+ Sa.[SA372 returns])*(1 + Sb.[SA372 returns])* (1+ Sc.[SA372 returns])*(1+ Sd.[SA372 returns]) as Compound 
FROM
    ((
      sheet1 Sa LEFT JOIN sheet1 Sb ON DATEADD("d",-1,DATEADD("m",-3,DATEADD("d",1,Sa.Date))) = Sb.Date)
                LEFT JOIN sheet1 Sc ON DATEADD("d",-1,DATEADD("m",-6,DATEADD("d",1,Sa.Date))) = Sc.Date)
                LEFT JOIN sheet1 Sd ON DATEADD("d",-1,DATEADD("m",-9,DATEADD("d",1,Sa.Date))) = Sd.Date
ORDER BY
    Sa.Date ASC  

注意: