在 VBA MS Access 中 运行 两个 SQL 查询。第二个记录集依赖于第一个记录集
Running two SQL queries in VBA MS Access. The second recordset depends on the first recordset
我目前正在使用 VBA 访问权限,我希望来自 strSQL 的信息来自 strSQL0。请帮我更正 strSQL 的 select 语句。
strSQL 的逻辑是我想select strSQL0
生成的记录器中的最小 iD
strSQL0 = "SELECT Promis_lt_generating_numbers_SubjectID_step2.* " _
& "FROM Promis_lt_generating_numbers_SubjectID_step2 LEFT JOIN PROMIS_LT ON Promis_lt_generating_numbers_SubjectID_step2.[Id] = PROMIS_LT.[DadosID]" _
& "WHERE (((PROMIS_LT.DadosID) Is Null));"
Set rs0 = dbs.OpenRecordset(strSQL0)
strSQL = "SELECT MIN(rs![Id]) AS New_SubjectID" _
& "FROM rs0![*];"
您可以 trim 第一个 SQL 提供价值,而无需第二个 SQL:
strSQL = "SELECT TOP 1 Id " & _
"FROM Promis_lt_generating_numbers_SubjectID_step2 " & _
"LEFT JOIN PROMIS_LT ON Promis_lt_generating_numbers_SubjectID_step2.[Id] = PROMIS_LT.[DadosID] " & _
"WHERE PROMIS_LT.DadosID Is Null " & _
"ORDER BY Id ASC;"
Set rs0 = dbs.OpenRecordset(strSQL)
SubjectID = rs0(0).Value
rs0.Close
我目前正在使用 VBA 访问权限,我希望来自 strSQL 的信息来自 strSQL0。请帮我更正 strSQL 的 select 语句。
strSQL 的逻辑是我想select strSQL0
生成的记录器中的最小 iDstrSQL0 = "SELECT Promis_lt_generating_numbers_SubjectID_step2.* " _
& "FROM Promis_lt_generating_numbers_SubjectID_step2 LEFT JOIN PROMIS_LT ON Promis_lt_generating_numbers_SubjectID_step2.[Id] = PROMIS_LT.[DadosID]" _
& "WHERE (((PROMIS_LT.DadosID) Is Null));"
Set rs0 = dbs.OpenRecordset(strSQL0)
strSQL = "SELECT MIN(rs![Id]) AS New_SubjectID" _
& "FROM rs0![*];"
您可以 trim 第一个 SQL 提供价值,而无需第二个 SQL:
strSQL = "SELECT TOP 1 Id " & _
"FROM Promis_lt_generating_numbers_SubjectID_step2 " & _
"LEFT JOIN PROMIS_LT ON Promis_lt_generating_numbers_SubjectID_step2.[Id] = PROMIS_LT.[DadosID] " & _
"WHERE PROMIS_LT.DadosID Is Null " & _
"ORDER BY Id ASC;"
Set rs0 = dbs.OpenRecordset(strSQL)
SubjectID = rs0(0).Value
rs0.Close