我试图将我的sql语句转换为vba但似乎没有任何效果

时间:2013-12-30 17:58:20

标签: access-vba

我正在尝试将mt sql语句转换为可用的vba代码,以便自动执行查询。但是,我似乎得到运行时错误3075:查询表达式中的语法错误(缺少运算符)(下面以粗体显示)。有人可以帮忙吗?

我在下面添加了我原来的SQL语句。我做错了什么?

谢谢!

Function Create_Queries()

Dim ticker1 As String
Dim ticker2 As String
Dim B As String
Dim A As String

ticker1 = EUF12
ticker2 = EUG12

SelectSQL = "SELECT DISTINCT CurrentDb.Series," & _
"CurrentDb.TimeStamp, CurrentDb.Trade," & _
"CurrentDb.BidOrAsk," & _
"CurrentDb.BestPrice," & _
"**CDbl(DateSerial((CInt(Left([TimeStamp],4))),(CInt(Mid([TimeStamp],6,2))),(CInt(Mid([TimeStamp],9,2))))+TimeSerial((CDbl(Mid([TimeStamp],12,2))),(CDbl(Mid([TimeStamp],15,2))),(CDbl(Mid([TimeStamp],18,6)))))+CDbl(Right([TimeStamp],4))*1/24/60/60" & _
"AS [DatenTime Value]**" & vbCrLf
fromSQL = "FROM CurrentDb"
wheresql = "WHERE (((CurrentDb.Series) = ticker1) And ((CurrentDb.Trade) Is Null) And ((CurrentDb.BidOrAsk) = B) And ((CurrentDb.BestPrice)><0) And ((CDbl(DateSerial((CInt(Left([TimeStamp], 4))), (CInt(Mid([TimeStamp], 6, 2))), (CInt(Mid([TimeStamp], 9, 2)))) + TimeSerial((CDbl(Mid([TimeStamp], 12, 2))), (CDbl(Mid([TimeStamp], 15, 2))), (CDbl(Mid([TimeStamp], 18, 6))))) + CDbl(Right([TimeStamp], 4)) * 1 / 24 / 60 / 60) < 40939))"
orderbysql = "ORDER BY CDbl(DateSerial((CInt(Left([TimeStamp],4))),(CInt(Mid([TimeStamp],6,2))),(CInt(Mid([TimeStamp],9,2))))+TimeSerial((CDbl(Mid([TimeStamp],12,2))),(CDbl(Mid([TimeStamp],15,2))),(CDbl(Mid([TimeStamp],18,6)))))+CDbl(Right([TimeStamp],4))*1/24/60/60;"
SQL = SelectSQL & vbCrLf & fromSQL & vbCrLf & wheresql & vbCrLf & orderbysql

CurrentDb.CreateQueryDef("Query1").SQL = SQL

End Function

SELECT [EU_201~1] .Series,[EU_201~1] .TimeStamp,[EU_201~1] .Trade,[EU_201~1] .BidOrAsk,[EU_201~1] .BestPrice,CDbl(DateSerial((CInt) (左([时间戳],4))),(CINT(MID([时间戳],6,2))),(CINT(MID([时间戳],9,2))))+ TimeSerial的((CDbl(中期([时间戳],12,2))),(CDbl(MID([时间戳],15,2))),(CDbl(MID([时间戳],18,6)))))+ CDbl(右([TimeStamp],4))* 1/24/60/60 AS DatenTime 来自[EU_201~1] WHERE((([EU_201~1] .Series)=“EUF12”)AND(([EU_201~1] .Trade)为空)AND(([EU_201~1] .BidOrAsk)=“B”)) 按CDbl排序(DateSerial((CInt(左([TimeStamp],4))),(CInt(Mid([TimeStamp],6,2))),(CInt(Mid([TimeStamp],9,2)) ))+ TimeSerial的((CDbl(MID([时间戳],12,2))),(CDbl(MID([时间戳],15,2))),(CDbl(MID([时间戳],18,6) ))))+ CDbl(右([时间戳],4))* 1/24/60/60;

1 个答案:

答案 0 :(得分:0)

这是我建议的简化调试过程

  1. 创建一个简单的选择查询并尝试运行它
  2. 使用debug.print确保您运行了正确的查询
  3. 使用空格代替vbcrlf
  4. 希望它能给你一些如何找出问题的想法