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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging the value from one query into another...

Status
Not open for further replies.

LittleMan22

Technical User
Jun 24, 2001
46
0
0
CA
I have a form on a web page that transfers values to another page to query an Access database. The first query uses form fields and returns a value called 'band' from the AllBand table (see below):

<% Option Explicit %>
<html>
<head>
<title>Bands</title>
</head>
<body>
<h2>Quick Quote</h2>
<ul>

<%
Dim dbBand
Dim rsBand
Dim oneRec
Dim Form_Amount
Dim Form_Plan

Form_Amount = Request.Form(&quot;Amount&quot;)
Form_Plan = Request.Form(&quot;Plan&quot;)

Set dbBand = Server.CreateObject(&quot;ADODB.Connection&quot;)
dbBand.Open(&quot;rates_131708&quot;)

oneRec = &quot;SELECT * FROM AllBands WHERE RateInfoID=2 AND Plan=&quot;&Form_Plan&&quot; AND MinAmount <= &quot;&Form_Amount&&quot; AND MaxAmount > &quot;&Form_Amount&&quot;&quot;

Set rsBand = Server.CreateObject(&quot;ADODB.Recordset&quot;)

rsBand.Open oneRec, dbBand

Do While Not rsBand.EOF

Response.Write &quot;<li><p>&quot; & rsBand(&quot;Band&quot;) & &quot;</p></li>&quot;
rsBand.MoveNext
Loop
If rsBand.BOF Then
Response.Write &quot;<p>No Entries in the database!</p>&quot; & VBCrLf
End If

rsBand.Close
dbBand.Close
%>

</ul>
</body>
</html>

So like I mentioned before this query is returning the value located in the band field. What I want it to do though is to copy this value into the following SQL query so that I can use it to query another table and return a different value (rate). Here's what that query needs to look like:

<%
Dim dbBand
Dim rsBand
Dim oneRec
Dim Form_Sex
Dim Form_Age
Dim Form_Plan

Form_Sex = Request.Form(&quot;Sex&quot;)
Form_Age = Request.Form(&quot;Age&quot;)
Form_Plan = Request.Form(&quot;Plan&quot;)

Set dbBand = Server.CreateObject(&quot;ADODB.Connection&quot;)
dbBand.Open(&quot;rates_131708&quot;)

oneRec = &quot;SELECT * FROM Can_Life WHERE RateInfoID=2 AND Sex=&quot;&Form_Sex&&quot; AND Class=0 AND Age=&quot;&Form_Age&&quot; AND Plan=&quot;&Form_Plan&&quot; AND Band=&quot;Value_from_1st_SQL&quot;&quot;

So somehow I have to insert the value that was returned from the first query into this second query (just so you know they are querrying different tables).


How do I write a 'joined' or 'double' query?

Thanks again,
-Ryan
 
In other words this is what I want to do:

I need to use the value that is retrieved from one query in another query. Here's the first query:

query1 = &quot;SELECT * FROM AllBands WHERE RateInfoID=2 AND Plan=&quot;&Form_Plan&&quot; AND MinAmount <= &quot;&Form_Amount&&quot; AND MaxAmount > &quot;&Form_Amount&&quot;&quot;

Here's the second:

query2 = &quot;SELECT Rate FROM Can_Life WHERE RateInfoID=2 AND Sex=&quot;&Form_Sex&&quot; AND Class=6 AND Age=&quot;&Form_Age&&quot; AND Plan=&quot;&Form_Plan&&quot; AND Renewal=0 AND Band=&quot;THE VALUE RETURNED FROM QUERY 1&quot;&quot;

How do I do this?

Thanks in advance,
-Ryan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top