473,769 Members | 7,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining two queries

I've got a question/request for the SQL gurus.
I'm building a model of bandwidth demand in MS Access and want to get
aggregated results for demand at each PCP in each time period.

The two queries below are used to count the number of households of each
Socio-Economic Type (each postcode has been allocated an SE-Type), and use
that to count the number of connections requiring a bandwidth less than 512
that will be required at the PCP in each month, and to put the results into
a table called PCP-Demands.

Unfortunately, my SQLing skills are somewhat limited, and I couldn't figure
out how to do this as a single query, so have had to put results into a temp
table, then pull them out again into my results table. It works, but
obviously it takes longer to run - I currently have a machine beside me that
has been grinding away since yesterday afternoon, and I don't expect to
finish today.

So, what I'm looking for is a way to combine the two queries below into one
query.
I'm sure it should be easy, but it's got me beat. If anyone could see their
way clear to combine these two queries for me, I'd be most appreciative.

Cheers,
Bruce.

Query to make temp table:
=============== =====
SELECT SED.Date, PC.PCP, SUM(pc.HouseHol ds * SED.[% <512]) AS Connections
INTO TempConnectionC ount
FROM ([SE-Demands] AS SED INNER JOIN [PostCodes Test] AS PC
ON PC.[SE-Type]=SED.[SE-Type])
GROUP BY [SED].Date, PC.PCP;
=============== =====

Query to put temp results into final table
=============== =====
UPDATE [PCP-Demands], TempConnectionC ount
SET [PCP-Demands].[Count <512] = TempConnectionC ount.Connection s
WHERE TempConnectionC ount.[Date] = [PCP-Demands].[Date]
AND TempConnectionC ount.[PCP] = [PCP-Demands].[PCP];
=============== =====

As a follow up, the closest I've managed to get so far is:

Attempt to combine the two queries
=============== =====
UPDATE [PCP-Demands], [SE-Demands], [PostCodes Test] SET
[PCP-Demands].[Count <512] = (
SELECT SUM([PostCodes Test].HouseHolds*[SE-Demands].[% <512])

FROM ([SE-Demands] INNER JOIN [PostCodes Test] ON [PostCodes
Test].[SE-Type]=[SE-Demands].[SE-Type])
)
WHERE [SE-Demands].Date=[PCP-Demands].[Date]
And [PostCodes Test].PCP=[PCP-Demands].[PCP];

=============== ==========
which comes up with the error "Operation must use an updateable query"
Suggestions really would be appreciated!
Nov 12 '05 #1
1 6013
On Thu, 6 Nov 2003 11:32:36 +0000 (UTC), "Bruce MacDonald"
<no***@noone.co m> wrote:

I don't think there is a better solution. I use the same method you
are. I agree Access is a bit stupid that it can't see I don't want to
modify data on the Group By side of the query (which legitimally is
not-updateable).
To optimize for speed, you may need an index on
TempConnectionC ount.[Date] and TempConnectionC ount.PCP.

-Tom.

I've got a question/request for the SQL gurus.
I'm building a model of bandwidth demand in MS Access and want to get
aggregated results for demand at each PCP in each time period.

The two queries below are used to count the number of households of each
Socio-Economic Type (each postcode has been allocated an SE-Type), and use
that to count the number of connections requiring a bandwidth less than 512
that will be required at the PCP in each month, and to put the results into
a table called PCP-Demands.

Unfortunatel y, my SQLing skills are somewhat limited, and I couldn't figure
out how to do this as a single query, so have had to put results into a temp
table, then pull them out again into my results table. It works, but
obviously it takes longer to run - I currently have a machine beside me that
has been grinding away since yesterday afternoon, and I don't expect to
finish today.

So, what I'm looking for is a way to combine the two queries below into one
query.
I'm sure it should be easy, but it's got me beat. If anyone could see their
way clear to combine these two queries for me, I'd be most appreciative.

Cheers,
Bruce.

Query to make temp table:
============== ======
SELECT SED.Date, PC.PCP, SUM(pc.HouseHol ds * SED.[% <512]) AS Connections
INTO TempConnectionC ount
FROM ([SE-Demands] AS SED INNER JOIN [PostCodes Test] AS PC
ON PC.[SE-Type]=SED.[SE-Type])
GROUP BY [SED].Date, PC.PCP;
============== ======

Query to put temp results into final table
============== ======
UPDATE [PCP-Demands], TempConnectionC ount
SET [PCP-Demands].[Count <512] = TempConnectionC ount.Connection s
WHERE TempConnectionC ount.[Date] = [PCP-Demands].[Date]
AND TempConnectionC ount.[PCP] = [PCP-Demands].[PCP];
============== ======

As a follow up, the closest I've managed to get so far is:

Attempt to combine the two queries
============== ======
UPDATE [PCP-Demands], [SE-Demands], [PostCodes Test] SET
[PCP-Demands].[Count <512] = (
SELECT SUM([PostCodes Test].HouseHolds*[SE-Demands].[% <512])

FROM ([SE-Demands] INNER JOIN [PostCodes Test] ON [PostCodes
Test].[SE-Type]=[SE-Demands].[SE-Type])
)
WHERE [SE-Demands].Date=[PCP-Demands].[Date]
And [PostCodes Test].PCP=[PCP-Demands].[PCP];

============== ===========
which comes up with the error "Operation must use an updateable query"
Suggestions really would be appreciated!


Nov 12 '05 #2

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

Similar topics

7
2797
by: frizzle | last post by:
Hi, I know this might sound strange but i think(/hope) it's quite simple: I'm running 2 queries in a mysql DB, first one returns 20 results. Now how can i echo results from the second query in the 1st query's result, like:
2
2111
by: SomeDude | last post by:
Lo group, I am wondering if there is a way of combining two SELECT statements into a single query. Here's the obligatory example to clarify things: SELECT id WHERE name=mike SELECT bills WHERE nameid=12 (12 being the result of the first query) Right now I am executing two separate calls and I would ofcourse like to
1
3211
by: ravi | last post by:
I have created the following interest to calculate the interest for the following currency pairs. I have tried to combine them in macros using conditions but the next query that is run in the macro ends up deleting the previous interest value that has been generated by the query. For example if query 1 is run on the table with currency pair USD/CHF then the interest will be updated without any problem but if there is another entry in the...
2
4162
by: BeruthialsCat | last post by:
I have 4 crosstabs which are keyed on a managerID field. I want to combine them to provide the data for a graph. I currently have them combined in a union query to produce 4 rows of data for each manager by month. What i think i need is to change the orientation so i have a column heading that represenst each crosstab, a manager ID column and a month column. So far ive thought of making a temp table using make table on one of the...
1
2068
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured query language, which forces me to do the join manually via arrays. Right now, I'm having trouble getting these query results (which are in
2
1479
by: billelev | last post by:
Does anyone know if it is possible to combine two queries that have the same fields? I basically want to combine a number of fields with the totals for those fields into one query (see example below). eg. If the original query contained four items: a, b, c and d, the resulting query or table combination would be: Name Amount a 1 b 2 c 3 d 4 ALL 10
7
2754
by: tcveltma | last post by:
Hi again, Ok, so I have about 15 crosstab queries. Each crosstab query is an employee's name. Within the query are the weeks as the column heading, the work order numbers as the row heading, and the hours as a value. Each query comes from a different employee table (1 table per employee). Is there any way I can combine all the queries into 1 query/report? So far it seems to me that the only way I'll have a chance at making every...
19
1839
by: Gilberto | last post by:
Hello I have created TWO different queries (for products belonging to FRONT and REAR) which use product information to filter the total (sum all belonging to the same category) of all the FRONT products belonging to every category. Same thing applies to the second query but just with products belonging to the REAR. The type of categories are the same for both queries (RED, BLUE, BLACK) and i just change the "CRITERIA" under the SEATING...
3
1555
by: billelev | last post by:
I am trying to combine two queries into one UNION query. The first sub-query works, but the second creates the following error at the end of the first iif statement: "Syntax error in union query" Does anybody know why? Select Symbol, MarketValue AS , Type, RiskType FROM . AS tmpVarPositions UNION SELECT Symbol, Sum(MarketValue), AlteredType as Type, RiskType
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
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 we have to send another system
2
3567
muto222
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.