Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 26th, 2015, 03:12 PM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pulling in results from first query into second

Hi guys

I have two sql queries on my page which queries two separate car tables. As an example, the first query simply queries table1 and returns any car models that are manufactured by Aston Martin.

-------------------
<%
sql = "Select model from table1 where manufacturer = 'aston martin'"

oRs.Open sql, oDBConn
If oRs.eof then

Else

Do while not oRs.eof

manufacturer = oRs("manufacturer")

oRs.MoveNext
loop

End If
%>
-------------------

So, I would get results like:

DB9
DB7
Vantage
Vanquish
DB5

so far so good....

The second query searches table2 for any records which match a set of car models, it would then display the top speed for each of those models. So...

-------------------
<%
sql = "Select model, topspeed from table2 WHERE model IN ('###', '###', '###')"

oRs.Open sql, oDBConn
If oRs.eof then

Else

Do while not oRs.eof
%>
<%=oRs("model")%> = <%=oRs("topspeed")%>
<%

oRs.MoveNext
loop

End If
%>
-------------------


Here's where I have my problem. I need to pull in the models from the first query into the "IN" statement in the second query. Thus it is executed as follows:


-------------------
sql = "Select model, topspeed from table2 WHERE model IN ('DB9', 'DB7', 'Vantage', 'Vanquish', 'DB5')"
-------------------

There is no set number of models. So, For a Porsche query, I may only have 3 models but for Audi I may have 13 models that need to be pulled into the second query.

I am an utter complete novice and have been looking at how I can do this for the past 3 days! The closest I have come is something called an array but this is way above my head. Is there an "easy" solution to this? Any help would be really appreciated.

I look forward to hearing from you

Best regards

Rod from the UK


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling out data -- very surprising results to a newbie... wsprague XSLT 4 May 7th, 2009 12:19 PM
query pulling null records jcarswelljr SQL Server 2005 2 March 20th, 2009 09:10 AM
Edit Query Results in Results Grid druid2112 SQL Server 2005 1 June 28th, 2007 08:49 AM
different results were given for the same query madhusrp SQL Server 2000 2 May 9th, 2006 01:54 AM
Date query pulling records from yesterday Justine Access 5 June 27th, 2004 03:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.