Avatar of mainrotor
mainrotor
 asked on

I need help with a VB function

Hi Experts,
I have a report that takes too long to generate.  Below is the fuctions that generates the report.
How can I update my function to speed it?
Could I use a static variable to speed it up?
Should I use Temp tables?

Sub Main()
   dim dt as datatable = "select * from orders,items where orders.itemid = item.itemid and invdate between Jan and Dec"
   for each dr as datarow in dt.rows
      call ProcFunc(dr)
   next dr
end sub
 
Sub ProcFunc(dr as datarow)
   dim dtProc as datatable = "select * from bigtable, itemdetail where bigtable.itemid = itemdetail.itemid and location = " & dr!location
   for each drSlowProc in dtProc.rows
       dim Cost as decimal = CalcLanded(dr!cost, drSlowProc!duty, dr!location)
       dim dtThis as datatable = "select * from hugetable where location = " & dr!location & " and Cost between 10 and 20"
       call OtherFunc(Cost, drThis)
   next drSlowProc
end sub

Open in new window


Thank you in advance,
mrotor
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
plusone3055

8/22/2022 - Mon
ChloesDad

Any process that has nested searches is going to be slow. Can you show us what you are trying to generate as this will allow us to perhaps come up with a better solution.
Qlemo

Using repetive SQL calls to get data is almost always a costly operation, because of the overhead involved for each SQL call.
So the first try is to make it a single SQL getting all data as required. And only the data required, that is you should restrict the columns to retrieve to allow for SQL, disk I/O, network I/O and memory optimization.

Also, in ProcFunc you are calling the SQL for hugetable in a loop though it does not have any changing parameters. You need to run that SQL only once per DR record, so move it infront of the FOR loop.
ASKER CERTIFIED SOLUTION
aikimark

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
plusone3055

the other thing you can do is Index the tables that you are calling to in SQL serer to Optimize the Query
Your help has saved me hundreds of hours of internet surfing.
fblack61