I am trying to create a stored procedure, which will iterate through each row/record of a SQL statement and for each iteration, it will insert all the records from a table into another.
I am from an Access background and I'm trying to migrate this code over to SQL. In Access VBA, the code looks something like below.
strSQL = "SELECT DISTINCT Field1, Field2 " _
& "FROM MyTable " _
& "WHERE ((([Field5]) Is Null Or (tblRXM.[Field7])<>'Unknown'));"
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
With rst
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
db.Execute "MyQuery", dbFailOnError
.MoveNext
Loop
End If
.Close
End With
Set rst = Nothing
I hope that makes sense. I need to be able to do that exact thing in a SQL stored procedure. I'm just starting to get my feet wet with this, so any assistance that you could provide, I'd appreciate. Thanks.