Currently I have approx 35000 records and for populating those records in Report I have to insert those records in a temprorary table through loop. But for this operation(insertion in temp table) its taking more than 8 min.currently I am using DAO connection.So how can I reduce the time for 1-2 min.The code is given below:- - Dim Dbs As Database
-
Dim rst As DAO.Recordset
-
Set Dbs = CurrentDb
-
Set rst = Dbs.OpenRecordset(ssql)
-
-
While Not rst.EOF
-
If IsNull(rst("Advisor Name")) Then
-
tmpAdvisorName = ""
-
Else
-
tmpAdvisorName = rst("Advisor Name")
-
End If
-
If IsNull(rst("Customer Name")) Then
-
tmpCustomerName = ""
-
Else
-
'tmpCustomerName = rst("Customer Name")
-
tmpCustomerName = Replace$(rst("Customer Name"), DoubleQuote, CHRDouble)
-
End If
-
If IsNull(rst("Country")) Then
-
tmpCountry = ""
-
Else
-
tmpCountry = rst("Country")
-
End If
-
If IsNull(rst("State")) Then
-
tmpState = ""
-
Else
-
tmpState = rst("State")
-
End If
-
If IsNull(rst("City")) Then
-
tmpCity = ""
-
Else
-
tmpCity = rst("City")
-
End If
-
-
If IsNull(rst("Job Title")) Then
-
tmpJobTitle = ""
-
Else
-
tmpJobTitle = rst("Job Title")
-
End If
-
If IsNull(rst("Unit Type")) Then
-
tmpUnitType = ""
-
Else
-
tmpUnitType = rst("Unit Type")
-
End If
-
If IsNull(rst("Activity")) Then
-
tmpActivity = ""
-
Else
-
tmpActivity = rst("Activity")
-
End If
-
If IsNull(rst("Arrival Date")) Then
-
tmpArrivalDate = ""
-
Else
-
tmpArrivalDate = rst("Arrival Date")
-
End If
-
If IsNull(rst("Depart Date")) Then
-
tmpDepartDate = ""
-
Else
-
tmpDepartDate = rst("Depart Date")
-
End If
-
If IsNull(rst("Unit Type2")) Then
-
tmpUnitType2 = ""
-
Else
-
tmpUnitType2 = rst("Unit Type2")
-
End If
-
If IsNull(rst("Unit Type3")) Then
-
tmpUnitType3 = ""
-
Else
-
tmpUnitType3 = rst("Unit Type3")
-
End If
-
If IsNull(rst("Unit Type4")) Then
-
tmpUnitType4 = ""
-
Else
-
tmpUnitType4 = rst("Unit Type4")
-
End If
-
If IsNull(rst("Unit Type5")) Then
-
tmpUnitType5 = ""
-
Else
-
tmpUnitType5 = rst("Unit Type5")
-
End If
-
ssql = "insert into [tblAdvanceReport_Temp] ([Advisor name], [Customer Name], Country, State, City, [Job title], [Unit Type], Activity,[Arrival Date],[Depart Date],"
-
ssql = ssql & " [Unit Type2], [Unit Type3], [Unit Type4], [Unit Type5]"
-
ssql = ssql & ") values "
-
ssql = ssql & "(" & Chr(34) & tmpAdvisorName & Chr(34) & ", " & Chr(34) & tmpCustomerName
-
ssql = ssql & Chr(34) & ", " & Chr(34) & tmpCountry & Chr(34) & ", " & Chr(34) & tmpState
-
ssql = ssql & Chr(34) & ", " & Chr(34) & tmpCity & Chr(34) & ", " & Chr(34) & tmpJobTitle
-
ssql = ssql & Chr(34) & ", " & Chr(34) & tmpUnitType & Chr(34) & ", " & Chr(34) & tmpActivity
-
ssql = ssql & Chr(34) & ", " & Chr(34) & tmpArrivalDate & Chr(34) & ", " & Chr(34) & tmpDepartDate
-
ssql = ssql & Chr(34) & ", " & Chr(34) & tmpUnitType2 & Chr(34) & ", " & Chr(34) & tmpUnitType3
-
ssql = ssql & Chr(34) & ", " & Chr(34) & tmpUnitType4 & Chr(34) & ", " & Chr(34) & tmpUnitType5 & Chr(34) & ")"
-
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL (ssql)
-
DoCmd.SetWarnings True
-
-
rst.MoveNext
-
Wend
-
-
rst.Close
2 1738
Why do you even loop through the recordset to begin with?
Why not simply do it in SQL? Example below: - ssql = "Insert Into [tblAdvanceReport_Temp] ([Advisor name], [Customer Name], Country, State, City, [Job title], [Unit Type], Activity,[Arrival Date],[Depart Date],"
-
ssql = ssql & " [Unit Type2], [Unit Type3], [Unit Type4], [Unit Type5])"
-
ssql = ssql & " SELECT [Advisor Name], [Customer Name] ......"
-
ssql = ssql & " FROM tbl_Main"
-
ssql = ssql & " WHERE ....."
-
Replace the .... with whatever is appropriate for you.
Another thing i notice, is all your if-statements. A simpler way of writing teh same is: - tmpCountry = nz(rst("Country"),"")
or - tmpCountry = rst("Country") & ""
I think the last of these two approaches may be the fastest, but I haven't actually tested.
A third approach can be to open a recordset to your temp table for examle: - Dim rstTemp as dao.Recordset
-
rstTemp=CurrentDb.Openrecordset(SELECT * FROM tblAdvanceReport_Temp",dbOpenDynaset)
-
-
Do While not rst.Eof
-
rstTemp.AddNew
-
rstTemp![Customer Name]=rst![Customer Name]
-
rstTemp![Advisor Name]=rst![Advisor Name]
-
rstTemp.Update
-
rst.MoveNext
-
Loop
-
set rstTemp=Nothing
Finally if your temporary table is indexed, and your inserts happen one at a time (as shown in your code) you might get a performance increase by removing the index in code, running the inserts, and then readding the index when the inserts are complete.
With all I've said here, I would still go with the first SQL option, unless that for some reason not shown here is not feasable.
Thanks a lot...I got the solution...
I modified the query as you suggested in the first case and now it is executing with in 1.15 min.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: boyopeg |
last post by:
I am working on an application with a sql server backend. the sql
performance always begins great, but decays quickly over time. if i
restart the sql service the performance shoots back up. The...
|
by: kk_oop |
last post by:
Hi. I wanted to use exceptions to handle error conditions in my code.
I think doing that is useful, as it helps to separate "go" paths from
error paths. However, a coding guideline has been...
|
by: jaggee |
last post by:
Hello,
This is regarding log analysis of a web system, I am finding my backend SQL programming has taken so much of time to process the application due to following quires for a log table having...
|
by: Roy Gourgi |
last post by:
Hi,
I am new to C#. I have the same time scheduling program written in C++ and
it is 5 times faster than my version in C#.
Why is it so slow as I thought that C# was only a little slower than...
|
by: kokul_k |
last post by:
Hi..
I'm facing a problem during inserting records in Mysql database. My
table consists of 9 fields. When i try to insert 1000 records to this
table using for loop it takes a lot of time.. nearly...
|
by: rxding |
last post by:
Can Java Store Procedure increase performance
Hello,
Performance reason we need to move some of our code into database. Java Store Procedure is given the first choice. However, while...
|
by: alexandru.nicau |
last post by:
Hello All,
I've got this huge class hierarchy (the naive solution to the
following cannot be accepted). Throughout the code I need to
instantiate a template wrapper class at several locations....
|
by: smuthuchitra |
last post by:
how do i get the count of records between 11PM and 1AM by day for the 10
days ?
|
by: mmcgarry.work |
last post by:
Hi,
I would like to follow Stroustrup's advice of separating an object
interface (abstract class) from an object implementation (concrete
class), See Section 15.2.5 in Stroustrup 3rd Edition.
...
|
by: paankhate |
last post by:
Hi,
I have a task at hand to reduce the time taken for search query to
execute. The query fetches records which will have to sorted by
degrees away from the logged in user. I have a function...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |