473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to reduce time(increase performance) for multiple insertion.

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:-

Expand|Select|Wrap|Line Numbers
  1. Dim Dbs As Database
  2. Dim rst As DAO.Recordset
  3. Set Dbs = CurrentDb
  4. Set rst = Dbs.OpenRecordset(ssql) 
  5.  
  6.     While Not rst.EOF
  7.         If IsNull(rst("Advisor Name")) Then
  8.             tmpAdvisorName = ""
  9.         Else
  10.             tmpAdvisorName = rst("Advisor Name")
  11.         End If
  12.         If IsNull(rst("Customer Name")) Then
  13.             tmpCustomerName = ""
  14.         Else
  15.             'tmpCustomerName = rst("Customer Name")
  16.             tmpCustomerName = Replace$(rst("Customer Name"), DoubleQuote, CHRDouble)
  17.         End If
  18.         If IsNull(rst("Country")) Then
  19.             tmpCountry = ""
  20.         Else
  21.             tmpCountry = rst("Country")
  22.         End If
  23.         If IsNull(rst("State")) Then
  24.             tmpState = ""
  25.         Else
  26.             tmpState = rst("State")
  27.         End If
  28.         If IsNull(rst("City")) Then
  29.             tmpCity = ""
  30.         Else
  31.             tmpCity = rst("City")
  32.         End If
  33.  
  34.         If IsNull(rst("Job Title")) Then
  35.             tmpJobTitle = ""
  36.         Else
  37.             tmpJobTitle = rst("Job Title")
  38.         End If
  39.         If IsNull(rst("Unit Type")) Then
  40.             tmpUnitType = ""
  41.         Else
  42.             tmpUnitType = rst("Unit Type")
  43.         End If
  44.         If IsNull(rst("Activity")) Then
  45.             tmpActivity = ""
  46.         Else
  47.             tmpActivity = rst("Activity")
  48.         End If
  49.         If IsNull(rst("Arrival Date")) Then
  50.             tmpArrivalDate = ""
  51.         Else
  52.             tmpArrivalDate = rst("Arrival Date")
  53.         End If
  54.         If IsNull(rst("Depart Date")) Then
  55.             tmpDepartDate = ""
  56.         Else
  57.             tmpDepartDate = rst("Depart Date")
  58.         End If
  59.         If IsNull(rst("Unit Type2")) Then
  60.             tmpUnitType2 = ""
  61.         Else
  62.             tmpUnitType2 = rst("Unit Type2")
  63.         End If
  64.         If IsNull(rst("Unit Type3")) Then
  65.             tmpUnitType3 = ""
  66.         Else
  67.             tmpUnitType3 = rst("Unit Type3")
  68.         End If
  69.         If IsNull(rst("Unit Type4")) Then
  70.             tmpUnitType4 = ""
  71.         Else
  72.             tmpUnitType4 = rst("Unit Type4")
  73.         End If
  74.         If IsNull(rst("Unit Type5")) Then
  75.             tmpUnitType5 = ""
  76.         Else
  77.             tmpUnitType5 = rst("Unit Type5")
  78.         End If       
  79.                 ssql = "insert into [tblAdvanceReport_Temp] ([Advisor name], [Customer Name], Country, State, City, [Job title], [Unit Type], Activity,[Arrival Date],[Depart Date],"
  80.         ssql = ssql & " [Unit Type2], [Unit Type3], [Unit Type4], [Unit Type5]"
  81.         ssql = ssql & ") values "
  82.         ssql = ssql & "(" & Chr(34) & tmpAdvisorName & Chr(34) & ", " & Chr(34) & tmpCustomerName
  83.         ssql = ssql & Chr(34) & ", " & Chr(34) & tmpCountry & Chr(34) & ", " & Chr(34) & tmpState
  84.         ssql = ssql & Chr(34) & ", " & Chr(34) & tmpCity & Chr(34) & ", " & Chr(34) & tmpJobTitle
  85.         ssql = ssql & Chr(34) & ", " & Chr(34) & tmpUnitType & Chr(34) & ", " & Chr(34) & tmpActivity
  86.         ssql = ssql & Chr(34) & ", " & Chr(34) & tmpArrivalDate & Chr(34) & ", " & Chr(34) & tmpDepartDate
  87.         ssql = ssql & Chr(34) & ", " & Chr(34) & tmpUnitType2 & Chr(34) & ", " & Chr(34) & tmpUnitType3
  88.         ssql = ssql & Chr(34) & ", " & Chr(34) & tmpUnitType4 & Chr(34) & ", " & Chr(34) & tmpUnitType5 & Chr(34) & ")"
  89.  
  90.         DoCmd.SetWarnings False
  91.         DoCmd.RunSQL (ssql)
  92.         DoCmd.SetWarnings True
  93.  
  94.         rst.MoveNext
  95.     Wend
  96.  
  97.     rst.Close
Sep 3 '10 #1
2 1738
TheSmileyCoder
2,322 Expert Mod 2GB
Why do you even loop through the recordset to begin with?

Why not simply do it in SQL? Example below:
Expand|Select|Wrap|Line Numbers
  1. ssql = "Insert Into [tblAdvanceReport_Temp] ([Advisor name], [Customer Name], Country, State, City, [Job title], [Unit Type], Activity,[Arrival Date],[Depart Date],"
  2.         ssql = ssql & " [Unit Type2], [Unit Type3], [Unit Type4], [Unit Type5])"
  3.         ssql = ssql & " SELECT [Advisor Name], [Customer Name] ......"
  4.         ssql = ssql & " FROM tbl_Main"
  5.         ssql = ssql & " WHERE ....."
  6.  
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:
Expand|Select|Wrap|Line Numbers
  1. tmpCountry = nz(rst("Country"),"")
or
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. Dim rstTemp as dao.Recordset
  2. rstTemp=CurrentDb.Openrecordset(SELECT * FROM tblAdvanceReport_Temp",dbOpenDynaset)
  3.  
  4. Do While not rst.Eof
  5.    rstTemp.AddNew
  6.    rstTemp![Customer Name]=rst![Customer Name]
  7.    rstTemp![Advisor Name]=rst![Advisor Name]
  8.    rstTemp.Update
  9.    rst.MoveNext
  10. Loop
  11. 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.
Sep 3 '10 #2
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.
Sep 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
59
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...
0
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...
29
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...
2
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...
0
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...
0
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....
1
by: smuthuchitra | last post by:
how do i get the count of records between 11PM and 1AM by day for the 10 days ?
2
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. ...
6
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.