新手求助,数据库查询语句

sSql = "Tag:R,(‘AA\A_1′),’" & UTCBeginTime & "’,’" & UTCEndTime & "’,"
sSql=sSql+"’order by Timestamp ASC’,’TimeStep=" & sVal.Value & ",1’"

1.我只想查开始时间A_1变量的一行数据(只要一个数据),请问查询语句怎么写
谢谢,感谢

最佳答案

查询完成后,ors.movefirst
写一次数据就好了
别用for循环
sSql = "Tag:R,(”PVArchive\NewTag”),”" & UTCBeginTime & "”,”" & UTCEndTime & "”,"
sSql=sSql+"”order by Timestamp ASC”,”TimeStep=" & sVal.Value & ",1”"
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
”填充数据到Excel中
Set oRs = oCom.Execute
m = oRs.RecordCount
If (m > 0) Then
oRs.MoveFirst
i=3
”下面就是填充第一条数据,开始时间的第一个数据
objExcelApp.Worksheets(sheetname).cells(i,1).value= oRs.Fields(0).Value
objExcelApp.Worksheets(sheetname).cells(i,2).value=
GetLocalDate(oRs.Fields(1).Value)
objExcelApp.Worksheets(sheetname).cells(i,3).value= oRs.Fields(2).Value
objExcelApp.Worksheets(sheetname).cells(i,4).value= oRs.Fields(3).Value
objExcelApp.Worksheets(sheetname).cells(i,5).value= oRs.Fields(4).Value

oRs.Close

截取了部分代码,这样应该就是写的第一条,写到EXCEL表格里面

提问者对于答案的评价:
谢谢

专家置评

已阅,最佳答案正确。

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc152513.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2017年6月5日 下午7:28
下一篇 2017年6月5日 下午7:29

相关推荐