Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using recordset value in where caluse of select statement

Status
Not open for further replies.

Lakki

Programmer
Sep 24, 2002
5
FR
Hi,

Please find below my code. I am trying to achieve the following :
I am getting a set of records in a recordset object (oRSp).
I am using each of the recordset object value in "where clause of another select statement" to get one more recordset object (oRSv) . If I hard code the value in the where clause of second select statement, code works fine.


<HTML>
<HEAD>
<TITLE>Report</TITLE>
</HEAD><BODY>
<H1>Persons in Organization</h1>
<%
dim oRSv,conn,per,co
Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.open &quot;DSN=sd4;userid=servicedesk;pwd=sd;&quot;
set oRSv=server.CreateObject(&quot;ADODB.Recordset&quot;)
query = &quot;select name_1 from v_organization;&quot;
oRSv.open query, conn
oRSv.MoveFirst
Response.Write &quot;<TABLE BORDER='1'>&quot;
Do while NOT oRSv.EOF
Response.Write &quot;<TR><TD>&quot; & oRSv(&quot;name_1&quot;) & &quot;</TD></TR>&quot;
dim temp
temp = &quot;'&quot; &oRSv(&quot;name_1&quot;)&&quot;';&quot;
per = &quot;select name from v_person where organization_name_1=&quot; &temp
set oRSp=server.CreateObject(&quot;ADODB.Recordset&quot;)
oRSp.open per,conn
oRSp.MoveFirst
Do while NOT oRSp.EOF
Response.Write &quot;<TR><TD>&quot; & oRSp(&quot;name&quot;) & &quot;</TD></TR>&quot;
oRSp.moveNext
Loop
oRSv.MoveNext
Loop
Response.Write &quot;</TABLE>&quot;
oRSv.close
set oRSv=nothing
%></BODY></HTML>

When I run this code, it displays the following error
Error Type:
ADODB.Recordset (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/test.asp, line 22

Please suggest me where I am going wrong.

Any help on this would be really great..

Thanks in advance
Lakki
 
After
Code:
oRSp.open per,conn[\code] you need to check and see that the recordset actually found data.

[code]
do while not oRSp.EOF
... code you have in the second Do While Loop
Loop
[\code]


It appears that no records are being returned for the value in the WHERE clause of the second SQL statement.

Hope this helps,

Thanks,

Gabe
 
Yes I have checked it out. If I use Response.write with the temp variable, I am able to observe the expected value of it in the browser.

So it is not a problem with the empty recordset from the 1st select statement. u are right that oRSp recordset does not have any records. This is what surprising to me since the temp variable has a value in it. If I execute the same in sqlplus, I am finding records returned by it.

Thanks
Lakki
 
After the line of code
Code:
 per = &quot;select name from v_person where organization_name_1=&quot; &temp
perform a
Code:
response.write per & &quot;<BR>&quot;

This will print out your sql statement that is returning no records.

Post this sql statement along with the hard coded sql statement that returns data.

Maybe I can see something by looking at the working and non-working sql statements.

Between these two lines of code
Code:
Loop
oRSv.MoveNext
You need to close the oRSp recordset and set it to nothing just like you do the oRSv recordset at the end of your code.


One more note. Move your
Code:
 dim temp
line of code outside your loop. You should only declare this variable once instead of everytime you run through the loop.

Thanks,

Gabe
 
Thank You.

You are right. One of the record in the recordset had null value. Hence I was getting this error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top