Given this code below which returns a first recordset (rs) based on a date range with some values that are then used in the second recordset (rs2) to sum up a cost. Further explanation is below the code:
strSQL = "SELECT job, suffix, isnull(qty_scrapped,0),isnull(qty_released,0), isnull(price,0),co_num FROM vwDashboardsQuality "
strSQL &= " WHERE trans_date >= '" & dtpStartDate.Value & "' AND trans_date <= '" & dtpEndDate.Value & "' "
rs = conn.Execute(strSQL)
While Not rs.EOF
strCONUM = Trim("" & rs("co_num").Value)
strSelectString = "SELECT ISNULL(a_cost,0) FROM jobmatl WHERE job='" & rs("job").Value & "' AND suffix = " & Format(rs("suffix").Value)
rs2 = conn.Execute(strSelectString)
While Not rs2.EOF
dblSumActualMaterialCost = dblSumActualMaterialCost + CDbl(rs2(0).Value)
rs2.MoveNext()
End While
rs2.Close()
rs2 = Nothing
rs.MoveNext()
End While
rs.Close()
rs = Nothing
I want to combine the queries into a single query so I am not hitting the database through the second recordset (rs2) just to sum up something that I know can be done in a single query.
Any tips would be helpful. Thank you in advance.