Re: most efficient way to use a stored proc within a loop?



thanks!

"Bob Barrows [MVP]" wrote:

MSUTech wrote:
Hello All,

What is the most efficient way to re-use paramaters within a loop?

Create and append the parameter objects BEFORE the loop (without setting
the values for the parameters whose values need to change in the loop).
Set the parameter values that depend on the loop cycle within the loop.
Probably the most efficient way is to instantiate object variables
referencing the parameter objects whose values need to change within the
loop.

set cmd=createobject("adodb.command")
dim parm1,parm2, ..., parmN
set parm1=cmd.createparameter("firstparm",...)
cmd.parameters.append parm1
set parm2=cmd.createparameter("secondparm",...)
cmd.parameters.append parm2
....

for ...
parm1.value = ...
parm2.value = ...
cmd.execute
next

If you are not reading the Return parameter value, and you are not using
output parameters, then you do not even need to use a Command object.

The technique I use most often is the
"procedure-as-connection-method" technique. With ADO 2.5 and higher,
stored procedures can be called as if they were native methods of the
connection object, like this:
conn.MyProcedure parmval1,...,parmvalN
This completely avoids the need to worry about delimiters, literal or
otherwise. Plus it turns out that this technique also causes the
procedure to be executed in a very efficient manner on the SQL Server
box.

You can also use this technique if your procedure returns a recordset:
set rs=server.createobject("adodb.recordset")
'optionally, set the cursor location and type properties
conn.MyProcedure parmval1,...,parmvalN, rs





--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



.



Relevant Pages

  • Re: Using DataReader to count rows
    ... The loop you have there does work. ... beforehand so that it end up not working, but that technique in general will ... > here helped me to realize the performance advantage of using data reader. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: wavread, performance due to memory allocation
    ... this technique is known as preallocation. ... Rather than forcing MATLAB ... to allocate more memory for a growing array each time through the FOR loop, ... preallocation forces MATLAB to allocate memory once before the FOR loop, ...
    (comp.soft-sys.matlab)
  • Re: most efficient way to use a stored proc within a loop?
    ... Create and append the parameter objects BEFORE the loop (without setting ... Plus it turns out that this technique also causes the ... Please reply to the newsgroup. ...
    (microsoft.public.data.ado)
  • Re: stopping a loop
    ... Quote- "You can also use this technique to have a loop that runs prior to ... > animations and slide advances are timed to advance without user input. ... hide all the slides NOT in the looping section. ...
    (microsoft.public.powerpoint)
  • Re: Solaris real-time thread capabilities
    ... All of my tests so far have been using empty loops! ... > get the timing right even on an empty loop... ... When using the spin loop technique, ...
    (comp.unix.solaris)