求大神指导SQL
Public Function LoadEQPDailyReport(Optional ByVal AreaNo As String = defString, Optional ByVal EquipmentNo As String = defString, _
Optional ByVal StartTime As Date = defDateTime, Optional ByVal EndTime As Date = defDateTime, Optional ByVal AdditionalXml As String = "") As String
Dim cnnTemp As OleDb.OleDbConnection
Dim daTemp As OleDb.OleDbDataAdapter
Dim dsTemp As DataSet
Dim drTemp As OleDb.OleDbDataReader
Dim strSQL As String
Dim StartEndTime As Double
Dim Rows() As DataRow
Try
'//Create connection
cnnTemp = objLic.CreateConnection(strConnectionString)
strSQL = "Select * From tblEQPStateBasis Order By EquipmentState"
cmmTemp = New OleDb.OleDbCommand(strSQL, cnnTemp)
drTemp = cmmTemp.ExecuteReader()
strSQL = " Select (Select ContainareaNo From tblSMDAreaRelation Where ObjectNo = Z.EquipmentNo And ObjectType = 2) AreaNo," & _
" (Select EquipmentType From tblEQPEquipmentBasis Where EquipmentNo = Z.EquipmentNo) EquipmentType," & _
" Z.EquipmentNo," & _
" 0 Moves"
StartEndTime = DateDiff(DateInterval.Second, StartTime, EndTime)
Do While drTemp.Read
If strDataBaseType = "oracle" Then
strSQL = strSQL & " ,Nvl(Round(( Select Sum(Least(A.EndTime,To_Date('" & Format(CDate(EndTime), "yyyy/MM/dd HH:mm:ss") & "','YYYY/MM/DD HH24:MI:SS')) -" & _
&