473,473 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

OK group, I am learning but still have a ways to go

Here are 4 different MS SQL query's:
Set rsVer = Server.CreateObject("ADODB.Recordset")
strSql = "Select p.Locality_Code, p.Name, Count(c.Locality_Code) as
Verified_Count From County AS p LEFT JOIN Verified as c on
p.Locality_Code=c.Locality_Code Group BY p.Locality_Code, p.Name ORDER BY
p.Locality_Code"
rsVer.Open strSQL, Conn

Set rsPetA = Server.CreateObject("ADODB.Recordset")
strSql = "Select p.Locality_Code, p.Name, Count(c.Locality_Code) as
PetA_Count From County AS p LEFT JOIN Verified as c on
p.Locality_Code=c.Locality_Code and PetA = 1 Group BY p.Locality_Code,
p.Name ORDER BY p.Locality_Code"
rsPet1.Open strSQL, Conn

Set rsPetB = Server.CreateObject("ADODB.Recordset")
strSql = "Select p.Locality_Code, p.Name, Count(c.Locality_Code) as
PetB_Count From County AS p LEFT JOIN Verified as c on
p.Locality_Code=c.Locality_Code and PetB = 1 Group BY p.Locality_Code,
p.Name ORDER BY p.Locality_Code"
rsPet2.Open strSQL, Conn

Set rsPetC = Server.CreateObject("ADODB.Recordset")
strSql = "Select p.Locality_Code, p.Name, Count(c.Locality_Code) as
PetC_Count From County AS p LEFT JOIN Verified as c on
p.Locality_Code=c.Locality_Code and PetC = 1 Group BY p.Locality_Code,
p.Name ORDER BY p.Locality_Code"
rsPet3.Open strSQL, Conn

Set rsPetD = Server.CreateObject("ADODB.Recordset")
strSql = "Select p.Locality_Code, p.Name, Count(c.Locality_Code) as
PetD_Count From County AS p LEFT JOIN Verified as c on
p.Locality_Code=c.Locality_Code and PetD = 1 Group BY p.Locality_Code,
p.Name ORDER BY p.Locality_Code"
rsPet4.Open strSQL, Conn

As you can see all are tapping the same tables for results but the 2nd, 3rd,
and 4th are filtering by a table if checked. How can I combine all 4 into 1
with the filters involved? Each query give me a result from 93 variables
showing Locality_Code (1 - 93), Name (Name of each Locality_Code) and then
the count, first total, then filtered by PetA, PetB, PetC, PetD. I'd like
to do a loop through to display the results but not sure if thats the best
way.

Thanks
Jeff
Jul 19 '05 #1
1 1206
Example of one query (QueryB) based on the results of another query
(QueryA):

QueryA = "SELECT CustID FROM tblCUSTOMERS WHERE CustName = 'A%'"

QueryB = "SELECT CustID, CustName FROM tblCUSTOMERS WHERE CustID IN (" &
QueryA & ")"

But the following is even faster and allows for more than one field to
be returned in QueryA:

QueryB = "SELECT tblCUSTOMERS.CustID, CustName FROM (" & strSQLA & ") AS
tblSQLA INNER JOIN tblCUSTOMERS ON tblSQLA.CustID = tblCUSTOMERS.CustID"

So QueryA would include all the CustID's for customers starting with A.

And QueryB would include more fields in the customers table (i.e. not
just the CustID field) for the records returned in QueryA (which was the
customers starting with A).

I suppose it wouldn't hurt to always use LEFT JOIN's in QueryB and build
from the tblSQLA on the left to other tables that have fields you want
to return.

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ggg | last post by:
I'm looking for a complete project/application done with heavy use of of object-oriented programming & design. Preferably something well documented and/or commented so that I can pick it apart...
3
by: kooolega | last post by:
Hi, that's me! I've decided to learn C++, but I'm still thinking about the books about C++. Which one is the best one and so on. I've made a list of books I'm going to read. I'd be glad if you...
19
by: What-a-Tool | last post by:
I have a school project (ASP) in which I have to call three different ASP pages from three different and identical (except for the form "action", obviously) HTM pages. This I have no problem with....
8
by: Mantorok | last post by:
Hi all I'm looking to learn C and/or C++ and I was wondering if there were any good on-line resources and books. I am currently a C# developer but I'm keen to discover C/C++ as I feel it...
7
by: Darin | last post by:
I have a report that sub-totals on a group, then grand-totals at the report footer. If there's only one group, the sub-total and grand total are redundant, so I only want to show one of them. I...
25
by: Shawn Ferguson | last post by:
I'm in the process of learning .NET but I have an issue. How do you know what CAN exist. What I mean is how does a person know to use the string.todate or something like that? There are so many...
26
by: mfasoccer | last post by:
I am sorry if this is an inappropriate place to put this post, if so please delete it. I am wondering about a few things. Do you guys recommend learning C as a second language, as someone who...
6
by: Killer42 | last post by:
I have actually asked a pretty similar question here in the past, without a great deal of success. But I've decided to try a different tack. So, what are the ways in which a network admin could...
13
by: ray | last post by:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/ <TITLE>HTML to Text...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.