p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_howto thread: Re: naming variables dynamically


Message #1 by "Ken Schaefer" <ken@a...> on Thu, 1 Aug 2002 12:56:56 +1000
Surely you could write a better SQL query, and solve the problem you are
having at the same time.

It seems to me that you want to get a list of all the unique ProgramWeeks
for a given UserID, and the average number of steps for each ProgramWeek

What's wrong with:

<%
strSQL = _
    "SELECT ProgramWeek, AVG(Steps) as AvgSteps " & _
    "FROM tblRecordSteps " & _
    "WHERE UserID = '" & session("UserID") & "' " & _
    "GROUP BY ProgramWeek"

objRS.Open strSQL, objConn

If not objRS.EOF then
    arrResults = objRS.getRows
End If
%>

Remember, that using "cursors", eg creating more recordsets in a loop, is
the easiest way to hobble a relational database - databases work best when
you use sets of data.

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Michael Robertson" <mike@m...>
Subject: [proasp_howto] naming variables dynamically


: Is it possible to name variables dynamically? I'm stuck.  I'm tryng to
loop
: through an array doing a sql statement on each item in array and store the
: results in a new variable each time. But how would I give it a unique name
: each time?
:
: strSQL="select distinct ProgramWeek from tblRecordSteps where userID ='" &
: session("userID") & "'"
: objRsSOpen strSQL
: NumWeeksArray=objRs.GetRows()
: objRs.Close
:
: Const intField=0
:
: For intWeeks = 0 to UBound(NumWeeksArray,2)
:      strSQL="select avg(Steps) as avgSteps from tblRecordSteps where
: ProgamWeek=" & NumWeeksArray       (intField,intWeeks) & " and userID ='"
&
: session("userID") & "'"
:      objRsSOpen strSQL
:     Dim newVar
:     newVar1=objRs("avgSteps")
:     objRs.Close
: Next
:
: Maybe there is a better way. Suggestions?
:
:


  Return to Index