Solved

Where part of the query

Posted on 2014-01-04
4
381 Views
Last Modified: 2014-01-04
I am trying to build a query and my "ON" part isn't working properly.

I only want this query for the values that have the identical FirstDay and DayRecorded. If those values are not the same, I don't want to include the data in the query. It keeps giving all the data even if the values are not the same. Thanks for any help you can provide!

SELECT qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, qryBookingDayswithYearIII.DayRecorded, Sum(qryBookingDayswithYearIII.ExtendedPrice) AS SumOfExtendedPrice
FROM qryBookingDayswithYear INNER JOIN qryBookingDayswithYearIII ON qryBookingDayswithYear.CustomerID = qryBookingDayswithYearIII.CustomerID
GROUP BY qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, qryBookingDayswithYearIII.DayRecorded;
0
Comment
Question by:cansevin
  • 2
4 Comments
 
LVL 39

Expert Comment

by:als315
Comment Utility
I see no join on these dates in your query. Have you tried to join them?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
you want to add the 2 fields in the join condition indeed:
SELECT qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, qryBookingDayswithYearIII.DayRecorded, Sum(qryBookingDayswithYearIII.ExtendedPrice) AS SumOfExtendedPrice
FROM qryBookingDayswithYear INNER JOIN qryBookingDayswithYearIII ON ( qryBookingDayswithYear.CustomerID = qryBookingDayswithYearIII.CustomerID
AND qryBookingDayswithYear.FirstDay = qryBookingDayswithYearIII.DayRecorded ) GROUP BY qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, qryBookingDayswithYearIII.DayRecorded; 

Open in new window

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
Comment Utility
Try with:

SELECT qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, qryBookingDayswithYearIII.DayRecorded, Sum(qryBookingDayswithYearIII.ExtendedPrice) AS SumOfExtendedPrice

FROM qryBookingDayswithYear INNER JOIN qryBookingDayswithYearIII ON qryBookingDayswithYear.CustomerID = qryBookingDayswithYearIII.CustomerID

HAVING qryBookingDayswithYear.FirstDay = qryBookingDayswithYearIII.DayRecorded

GROUP BY qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, qryBookingDayswithYearIII.DayRecorded;

or replace HAVING  with WHERE.

/gustav
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now