473,474 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trying to combine Two queries into One Query.. Need Help!

Hi, I am trying to match two queries and make it into one query. I
have only been about to group similar attributes but nothing that
looks like the FinalQuery below. If anyone knows of a query that
would create the final result that would be great. Thanks in advance.

The FIRSTQUERY looks like this

Month Week OpenedCount
May Week: 3 3
May Week: 4 6
Jun Week: 1 4
Jun Week: 2 2
Jul Week: 3 4
The SECONDQUERY looks like this

Month Week ClosedCount
Apr Week: 1 2
Apr Week: 2 4
Oct Week: 4 3
Oct Week: 1 5
Dec Week: 3 4
Dec Week: 4 2
The FINAL RESULT I am looking for is

Month Week OpenedCount ClosedCount
Apr Week: 1 0 2
Apr Week: 2 0 4
May Week: 3 3 0
May Week: 4 6 0
Jun Week: 1 4 0
Jun Week: 2 2 0
Jul Week: 3 4 0
Oct Week: 4 0 3
Oct Week: 1 0 5
Dec Week: 3 0 4
Dec Week: 4 0 2
Nov 13 '05 #1
3 2023
Here is the SQL for the Open and Closed Queries, thanks in Advance.

ClosedQuery

SELECT Format(([Altered Date]),"mmm") & " " & Format(([Altered
Date]),"yyyy") AS MonthYear, "Week: " & GetWeekNumberInMonth([Altered
Date]) AS CheckWeek, Count(CLOSEDPMRDATES.[Altered Date]) AS OpenCount
FROM CLOSEDPMRDATES
GROUP BY Format(([Altered Date]),"mmm") & " " & Format(([Altered
Date]),"yyyy"), "Week: " & GetWeekNumberInMonth([Altered Date]),
Year([Altered Date]), Month([Altered Date])
ORDER BY Year([Altered Date]), Month([Altered Date]);

Represent this

MonthYear Week OpenCount
Apr Week: 1 2
Apr Week: 2 4
Oct Week: 4 3
Oct Week: 1 5
Dec Week: 3 4
Dec Week: 4 2
------------------
OpenQuery

SELECT Format(([Open Date]),"mmm") & " " & Format(([Open
Date]),"yyyy") AS MonthYear, "Week: " & GetWeekNumberInMonth([Open
Date]) AS CheckWeek, Count(OPENPMRDATES.[Open Date]) AS ClosedCount
FROM OPENDATES
GROUP BY Year([Open Date]), Month([Open Date]), Format(([Open
Date]),"mmm") & " " & Format(([Open Date]),"yyyy"), "Week: " &
GetWeekNumberInMonth([Open Date])
ORDER BY Year([Open Date]), Month([Open Date]);

Represents this

Month Week ClosedCount
May Week: 3 3
May Week: 4 6
Jun Week: 1 4
Jun Week: 2 2
Jul Week: 3 4
And I would like the final result to look like this:

Month Week OpenedCount ClosedCount
Apr Week: 1 0 2
Apr Week: 2 0 4
May Week: 3 3 0
May Week: 4 6 0
Jun Week: 1 4 0
Jun Week: 2 2 0
Jul Week: 3 4 0
Oct Week: 4 0 3
Oct Week: 1 0 5
Dec Week: 3 0 4
Dec Week: 4 0 2
Nov 13 '05 #2
al******@hotmail.com (Alicia) wrote in message news:<d3**************************@posting.google. com>...
Hi, I am trying to match two queries and make it into one query. I
have only been about to group similar attributes but nothing that
looks like the FinalQuery below. If anyone knows of a query that
would create the final result that would be great. Thanks in advance.


This is a hack, but it worked:

SELECT theMonth, theWeek, OpenedCount, 0 As ClosedCount,
Month([theMonth] & ' 1 2000') As MonthNum FROM FIRSTQUERY UNION SELECT
theMonth, theWeek, 0 AS OpenedCount, ClosedCount, Month([theMonth] & '
1 2000') As MonthNum FROM SECONDQUERY ORDER BY MonthNum, theWeek;

Note: I changed your Month and Week fields to theMonth and theWeek.

James A. Fortune
Nov 13 '05 #3
al******@hotmail.com (Alicia) wrote in message news:<d3**************************@posting.google. com>...
Here is the SQL for the Open and Closed Queries, thanks in Advance.


I see what you're trying to do now. You want to create a single SQL
statement that groups and sums information from your two base tables
directly into your final result table. Your first post neglected the
year information and gave no clue about any base table fields. I'd
say give it another try using a Union Query with matching field names
in the same order for both SELECT parts. If you still need help post
again including the SQL you tried. Also, it seems odd to include the
'Week: ' text inside the field.

James A. Fortune
Nov 13 '05 #4

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

Similar topics

5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
0
by: MostlyH2O | last post by:
Hi Folks, I have a complex query that references a sub-query. It works fine when I call a sub-query from the main query (using design vew), but when I try to embed the SQL text of the...
4
by: Jason Gyetko | last post by:
Is there any way to combine these two queries into one? I have tables Item_Master & Kit_Master which are the source tables. Query 2 is using both Item_Master (table) & qryKit1 (query) &...
7
by: Mintyman | last post by:
Hi, I'm working on a system migration and I need to combine data from multiple rows (with the same ID) into one comma separated string. This is how the data is at the moment: Company_ID ...
4
by: PlayHard | last post by:
I want my output in two columns like this: C_INCIDENT_TYPE \ TOTAL COUNT How do I combine my two queries to get result. First Query SELECT C_INCIDENT_TYPE, COUNT (*)
46
by: dude88888 | last post by:
Hello I have one query where i get the total number of units for an entire fund say fund 89 has 1000 total units Then i need to find out how much of the total fund each user has say user...
4
by: | last post by:
I have query1 where I set a date range. Query2 is a crosstab query and is based on query1. I don't want the queries to be saved in the mdb but I do want them to be run in VBA using a querystring. If...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
2
by: bips2005 | last post by:
i have got two queries, $sql1 = "select cust_id from customer where comp_name = '$compname'"; $result = $DB->query($sql1); $result->fetchInto($row); $sql = "select expirydate from...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
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,...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.