我有一个select语句需要引入数据库中的所有labnumber。但是有大约3000条记录,我想知道是否有更快的方法来做到这一点?这是代码。
Try
Dim labnumber As SqlCommand
If GenStoredProcs.Location = "CL" Then
labnumber = New SqlCommand("SELECT * FROM MAT_SAMPLE_TRACKING " &
"WHERE LABNO IN " &
"(SELECT DISTINCT LABNO FROM MAT_MAIN_GLASS_BEADS " &
"UNION SELECT DISTINCT LABNO FROM MAT_MAIN_CYLINDER " &
"UNION SELECT DISTINCT LABNO FROM MAT_SHRP_MAIN " &
"UNION SELECT DISTINCT LABNO FROM MAT_PAINT_WATERBORNE " &
"UNION SELECT DISTINCT LABNO FROM MAT_STOREROOM_BLEND " &
"UNION SELECT DISTINCT LABNO FROM MAT_STONEROOM_INFO " &
"UNION SELECT DISTINCT LABNO FROM MAT_PAINT_EPOXY " &
"UNION SELECT DISTINCT LABNO FROM MAT_WINTER_COARSE_MAIN " &
"UNION SELECT DISTINCT LABNO FROM MAT_WINTER_FINE_MAIN " &
"UNION SELECT DISTINCT LABNO FROM MAT_FINE_AGGREGATE " &
"UNION SELECT DISTINCT LABNO FROM MAT_REBAR_INFO) " &
"ORDER BY LABNO DESC ", modData.MATDB_Connection)
Else
'Load Tests table, only labs that have tests
labnumber = New SqlCommand("SELECT * FROM MAT_SAMPLE_TRACKING " &
"WHERE LABNO IN " &
"(SELECT DISTINCT LABNO FROM MAT_MAIN_ASPHALT " &
"UNION SELECT DISTINCT LABNO FROM MAT_MAIN_CONCRETE " &
"UNION SELECT DISTINCT LABNO FROM MAT_MAIN_BRICKS " &
"UNION SELECT DISTINCT LABNO FROM MAT_MAIN_GLASS_BEADS " &
"UNION SELECT DISTINCT LABNO FROM MAT_MAIN_RICE " &
"UNION SELECT DISTINCT LABNO FROM MAT_MAIN_WET_WASH " &
"UNION SELECT DISTINCT LABNO FROM MAT_MAIN_PRECAST) " &
"ORDER BY LABNO DESC ", modData.MATDB_Connection)
End If
'removed from else condition above should not be needed
'"UNION SELECT DISTINCT LABNO FROM MAT_SHRP_MAIN " & _
'"UNION SELECT DISTINCT LABNO FROM MAT_PAINT_WATERBORNE) " & _
Dim reader As SqlDataReader = labnumber.ExecuteReader()
If reader.HasRows Then
While reader.Read()
If Not IsDBNull(reader("LABNO")) Then
cboLabNumber.Items.Add(reader("LABNO"))
End If
End While
End If
reader.Close()