G
Guest
Hi,
I have tblProduct with 100,000 records and with columns like ProdID, Cost,
QtyRemained
I have a tblInvoiceDetail with 10,000 records and with columns like ProdID,
ProdCost, SalesQty, ....
Now, I have to loop through tblInvoiceDetail and get the Cost from
tblProduct for every row in tblInvoiceDetail.
Which Approach is faster - 1 or 2 ?
Approach 1:-
set rstInvoiceDetail = dbs.OpenRecordset("Select * from tblInvoiceDetail",
dbOpenDynaset, dbseechanges)
set rstProd = dbs.Openrecordset("Select * from tblProduct",dbOpenDynaset,
dbseechanges)
Do while rstInvoiceDetail.eof
rstProd.FindFirst "strProductID = """ & rstInvoiceDetail("strProductID") &
""""
rstInvoiceDetail.Edit
rstInvoiceDetail("ProdCost") = rstProd("Cost")
rstInvoiceDetail.Update
rstInvoiceDetail.MoveNext
Loop
Approach 2:-
set rstInvoiceDetail = dbs.OpenRecordset("Select * from tblInvoiceDetail",
dbOpenDynaset, dbseechanges)
Do while rstInvoiceDetail.eof
strSQL = "Select * from tblProduct where strProductID = """ &
rstInvoiceDetail("strProductID") & """"
set rstProd = dbs.Openrecordset(strSQL,dbOpenDynaset, dbseechanges)
rstInvoiceDetail.Edit
rstInvoiceDetail("ProdCost") = rstProd("Cost")
rstInvoiceDetail.Update
rstInvoiceDetail.MoveNext
Loop
Thank You
Woo
I have tblProduct with 100,000 records and with columns like ProdID, Cost,
QtyRemained
I have a tblInvoiceDetail with 10,000 records and with columns like ProdID,
ProdCost, SalesQty, ....
Now, I have to loop through tblInvoiceDetail and get the Cost from
tblProduct for every row in tblInvoiceDetail.
Which Approach is faster - 1 or 2 ?
Approach 1:-
set rstInvoiceDetail = dbs.OpenRecordset("Select * from tblInvoiceDetail",
dbOpenDynaset, dbseechanges)
set rstProd = dbs.Openrecordset("Select * from tblProduct",dbOpenDynaset,
dbseechanges)
Do while rstInvoiceDetail.eof
rstProd.FindFirst "strProductID = """ & rstInvoiceDetail("strProductID") &
""""
rstInvoiceDetail.Edit
rstInvoiceDetail("ProdCost") = rstProd("Cost")
rstInvoiceDetail.Update
rstInvoiceDetail.MoveNext
Loop
Approach 2:-
set rstInvoiceDetail = dbs.OpenRecordset("Select * from tblInvoiceDetail",
dbOpenDynaset, dbseechanges)
Do while rstInvoiceDetail.eof
strSQL = "Select * from tblProduct where strProductID = """ &
rstInvoiceDetail("strProductID") & """"
set rstProd = dbs.Openrecordset(strSQL,dbOpenDynaset, dbseechanges)
rstInvoiceDetail.Edit
rstInvoiceDetail("ProdCost") = rstProd("Cost")
rstInvoiceDetail.Update
rstInvoiceDetail.MoveNext
Loop
Thank You
Woo