Help: Is there a better way?

Help: Is there a better way?

am 22.09.2005 15:21:39 von bill

Hi All,

I started this report pulling from a SQL Server 2000 db. I'm pulling to
recordsets, the second based off the results of the first. So really,
its an rs loop within an rs loop. It works alright but man its so slow,
I dont think it will be acceptable. I wanted to know if there is a more
efficient way to code this?

Here's my code...

type="text" class="Fetching" value="">

<%
strInitForm = Request.Form("initForm")
strSelRegion = Request.Form("Region")
strRegSel = Request.Form("Region")
response.write(strInitForm & ", " & strSelRegion & ", " & strRegSel)

Select Case strSelRegion
Case "1"
response.Write("All Regions")
strRegion = ""
Case "2"
response.Write("Atlanta Telesales")
strRegion = "Atlanta Telesales"
Case "3"
response.Write("Canada Telesales")
strRegion = "Canada Telesales"
Case "4"
response.Write("Central Region")
strRegion = "Central Region"
Case "5"
response.Write("Channel Sales")
strRegion = "Channel Sales"
Case "6"
response.Write("Eastern Region")
strRegion = "Eastern Region"
Case "7"
response.Write("Raleigh Telesales")
strRegion = "Raleigh Telesales"
Case "8"
response.Write("Strike Team")
strRegion = "Strike Team"
Case "9"
response.Write("Western Region")
strRegion = "Western Region"
End Select
%>

">



onClick="selectRegion();">


<%

db1 = "Driver={SQL
Server};UID=SomeUser;password=SomePassword;DATABASE=PCICommo n;SERVER=127.0.0.1"
sqlStr1="SELECT DISTINCT tblResourceInfo.strLastName,
tblResourceInfo.strFirstName, tblResourceInfo.strEmail,
tblSalesData.strSalesRegion FROM PCICommon.dbo.tblResourceInfo
tblResourceInfo, PCICommon.dbo.tblSalesData tblSalesData WHERE
tblSalesData.strEmail = tblResourceInfo.strEmail AND
((tblSalesData.strSalesRegion='" & strRegion & "')) ORDER BY
tblResourceInfo.strLastName"

set rsTemp1 = Server.CreateObject("ADODB.Recordset")
rsTemp1.CursorLocation = 3 ' adUseClient
rsTemp1.Open sqlStr1, db1

do until rsTemp1.EOF
response.write rsTemp1.Fields("strLastName") & ", " &
rsTemp1.Fields("strFirstName") & "
"

'Begin second recordset based on e-mail addresses in rsTemp1 here
strStudentEmail = rsTemp1.Fields("strEmail")
sqlStr2="SELECT tblResourceInfo.strEmail, tblClass.strCourseCode,
tblClass.strCourseTitle, tblClass.dtnStartDate,
tblEnrollment.dtnCompleted, tblEnrollment.lngStudentID FROM
ClassSchedule.dbo.tblClass tblClass, ClassSchedule.dbo.tblEnrollment
tblEnrollment, PCICommon.dbo.tblResourceInfo tblResourceInfo WHERE
tblEnrollment.lngStudentID = tblResourceInfo.lngResourceID AND
tblClass.lngClassID = tblEnrollment.lngClass AND
tblResourceInfo.strEmail ='" & strStudentEmail & "'"

set rsTemp2 = Server.CreateObject("ADODB.Recordset")
rsTemp2.Open sqlStr2, db1
response.Write strStudentEmail & "
"

response.Write "strCourseCode, dtnStartDate, dtnCompleted, lngStudentID

"
do until rsTemp2.EOF
response.write rsTemp2.Fields("strCourseCode") & ", " &
rsTemp2.Fields("dtnStartDate") & ", " & rsTemp2.Fields("dtnCompleted")
& ", " & rsTemp2.Fields("lngStudentID") & "
"
rsTemp2.MoveNext
loop

rsTemp2.close
set rsTemp2 = nothing

rsTemp1.MoveNext
loop

rsTemp1.close
set rsTemp1 = nothing
set db1 = nothing
%>

Thanks in advance for your responses!

Re: Is there a better way?

am 22.09.2005 16:51:20 von reb01501

bill wrote:
> Hi All,
>
> I started this report pulling from a SQL Server 2000 db. I'm pulling
> to recordsets, the second based off the results of the first. So
> really, its an rs loop within an rs loop. It works alright but man
> its so slow, I dont think it will be acceptable. I wanted to know if
> there is a more efficient way to code this?
>
There is probably a way to constuct a query to avoid the inefficient rs
loops. Unfortunately, without any details about your table structure(s), or
what you wish the outcome to look like, it's impossible to make suggestions
without spending a lot of time trying to reverse-engineer it from your code
(something I am not ready to do). Please provide table-creation scripts
(DDL) and sample data per the suggestions mentioned in www.aspfaq.com/5006.
And make sure you show us what the output from that sample data needs to
look like (don't just describe it - show us)

In the meantime, you should read:
http://www.aspfaq.com/show.asp?id=2201

As well as this:
http://tinyurl.com/jyy0
which will show you how to avoid the threat of sql injection by using
parameters instead of dynamic sql

Also, nothing to do with your problem but you should read:
http://www.aspfaq.com/show.asp?id=2126

Bob Barrows
--
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.

Re: Is there a better way?

am 22.09.2005 17:44:29 von bill

Well I don't have access to the SQL server to generate the scripts
you're talking about, I'm just given the task of coding it. so thanks
for nothing I guess.

Re: Is there a better way?

am 22.09.2005 18:52:55 von rdanjou

"bill" wrote in message
news:1127403869.839800.164260@g44g2000cwa.googlegroups.com.. .
.... so thanks for nothing I guess.

Now that was uncalled for.
And you'll never get much help with that attitude.

Re: Is there a better way?

am 22.09.2005 19:38:08 von bill

So tell my mommy... in the length of time the prick (judging by his
other posts) took to spew his bureaucracy he could have given an
answer. This wasn't a difficult question and you don't need test data
to judge whether someones coding is optimized for performance - gfys

Re: Is there a better way?

am 22.09.2005 19:50:23 von rdanjou

"bill" wrote in message
news:1127410688.710888.79970@z14g2000cwz.googlegroups.com...
> So tell my mommy...
Somebody should.

> in the length of time the prick (judging by his
> other posts) took to spew his bureaucracy he could have given an
> answer.
He did give you an answer.
Did you even read the links?

> This wasn't a difficult question and you don't need test data
> to judge whether someones coding is optimized for performance -
www.aspfaq.com/5006... again

>gfys
*PLONK*

Re: Is there a better way?

am 22.09.2005 20:18:16 von bill

troll

Re: Is there a better way?

am 22.09.2005 22:07:03 von reb01501

bill wrote:
> Well I don't have access to the SQL server to generate the scripts
> you're talking about, I'm just given the task of coding it. so thanks
> for nothing I guess.

Well that's kind of silly. Instead of figuring out a different way to
provide the information I requested (or asking us to suggest an alternative
method), you simply decide to flame me ...?

plonk
--
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.

Re: Is there a better way?

am 22.09.2005 22:54:52 von bill

well, boss was pretty cranky today and that obviously came through loud
and clear in my texts. Truth be known the table content is classified
so your answer wasn't an option for me. But I did manage to clean it up
and speed it up today using your links. Thanks.