這個問題我自已做到了基本要求,我的笨辦法用了3個RS循還的查取結果,求改進優化辦法
For n7 = 1 To 4
Select Case n7
Case 1
a6 = a1
Case 2
a6 = a2
Case 3
a6 = a3
Case 4
a6 = a4
End Select
rs.Close
rss.Close
rsss.Close
sql1 = "select max(字段1)/max(字段2) from " & mytable & " where 類別 = '" & a6 & "' and 日期 = '" & n5 & "'"
sql2 = "select max(字段3) from " & mytable & " where 類別 = '" & a6 & "' and 日期 = '" & n5 & "'"
sql3 = "select max(字段4)/10 from " & mytable & " where 類別 = '" & a6 & "' and 日期 = '" & n5 & "'"
rs.Open sql1, conn, 1, 3
rss.Open sql2, conn, 1, 3
rsss.Open sql3, conn, 1, 3
If rs.RecordCount < 1 Then
xlSheet1.Cells(100 + n7, 2) = ""
Else
xlSheet1.Cells(100 + n7, 2) = rs.Fields(0)
End If
If rss.RecordCount < 1 Then
xlSheet1.Cells(110 + n7, 2) = ""
Else
xlSheet1.Cells(110 + n7, 2) = rss.Fields(0)
End If
If rsss.RecordCount < 1 Then
xlSheet1.Cells(120 + n7, 2) = ""
Else
xlSheet1.Cells(120 + n7, 2) = rsss.Fields(0)
End If
Next