Where Dates are equal

I have the below query that I am using. The problem is want it only when DateRecorded is equal to FirstDay. First Day is a date in the form of 01-01-2014 and date recorded is in the form: 8/18/2014 11:55:24 AM. How can I see results were Firsday and DateRecorded are the same date? Thanks!

SELECT qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, Sum([Booking Details Extended].ExtendedPrice) AS SumOfExtendedPrice, [Booking Details Extended].DateRecorded
FROM qryBookingDayswithYear INNER JOIN [Booking Details Extended] ON qryBookingDayswithYear.CustomerID = [Booking Details Extended].CustomerID
GROUP BY qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, [Booking Details Extended].DateRecorded;

Open in new window

cansevinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
Is the qryBookingDayswithYear.FirstDay column type TEXT or DATE? Your query may have just the "format" setting to show it like this. The actual data maybe DATE.
If the column is indeed the date column then this query will do the trick:
SELECT qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, Sum([Booking Details Extended].ExtendedPrice) AS SumOfExtendedPrice, [Booking Details Extended].DateRecorded
FROM qryBookingDayswithYear INNER JOIN [Booking Details Extended] ON qryBookingDayswithYear.CustomerID = [Booking Details Extended].CustomerID
WHERE DateValue(qryBookingDayswithYear.FirstDay) = DateValue([Booking Details Extended].DateRecorded)
GROUP BY qryBookingDayswithYear.CustomerID, qryBookingDayswithYear.FirstDay, [Booking Details Extended].DateRecorded;

Open in new window

0
Gustav BrockCIOCommented:
This will work:
SELECT 
    qryBookingDayswithYear.CustomerID, 
    qryBookingDayswithYear.FirstDay, 
    Sum([Booking Details Extended].ExtendedPrice) AS SumOfExtendedPrice, 
    [Booking Details Extended].DateRecorded
FROM 
    qryBookingDayswithYear 
INNER JOIN 
    [Booking Details Extended] 
    ON qryBookingDayswithYear.CustomerID = [Booking Details Extended].CustomerID
GROUP BY 
    qryBookingDayswithYear.CustomerID, 
    qryBookingDayswithYear.FirstDay, 
    [Booking Details Extended].DateRecorded
HAVING
    qryBookingDayswithYear.FirstDay = Fix([Booking Details Extended].DateRecorded);

Open in new window

or, if you prefer:
HAVING
    DateDiff("d", qryBookingDayswithYear.FirstDay, [Booking Details Extended].DateRecorded) = 0;

Open in new window

or, if the dates are text:
HAVING
    DateValue(qryBookingDayswithYear.FirstDay) = DateValue([Booking Details Extended].DateRecorded);

Open in new window

/gustav
0
Dale FyeOwner, Developing Solutions LLCCommented:
@Gustav,

"or if the dates are text"?

Why only if the dates are text?  DateValue( ) basically strips the time portion of a Date/Time datatype and can be used to compare simple Date() values with those that include time values.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dale FyeOwner, Developing Solutions LLCCommented:
@cansevin,

Another method, although longer, would be:

WHERE (qryBookingDayswithYear.FirstDay <= [Booking DetailsExtended].DateRecorded)
AND ([Booking DetailsExtended].DateRecorded < qryBookingDayswithYear.FirstDay + 1)

Open in new window


The other examples simply use either the Fix( ) or the DateValue( ) functions to strip the time portion of the [DateRecorded] value and compare the integer portion of those fields.
0
Gustav BrockCIOCommented:
> Why only if the dates are text?

Because [First Date] doesn't have a time part.

/gustav
0
Dale FyeOwner, Developing Solutions LLCCommented:
@Gustav,

I'm not nit-picking here, just trying to understand your logic.
Why only if the dates are text?  the OP indicated that [FirstDay] is a date only value.  The DateValue function works with both text (if formatted properly) and date data types.  You simply would not need to use the DateValue([FirstDay]) since that value is already in the mm/dd/yy format.

In your example:

HAVING
    qryBookingDayswithYear.FirstDay = DateValue([Booking Details Extended].DateRecorded);

Open in new window


And for clarification, why process the criteria after the grouping, with a HAVING clause, instead of before the aggregation, with a WHERE clause?
0
Gustav BrockCIOCommented:
I don't follow ... if FirstDate is of data type Date and has not time part, why would you use DateVaue on this?

Yes, perhaps you can use WHERE in place of HAVING. I just picked what first came to my mind.

/gustav
0
cansevinAuthor Commented:
Thanks Guys... Gustav, your's seems to work. Only issue is it is grouping it one to many ways. Any way to get it to group without the DateRecorded. So it sums the FirstDay. As of now each day is seperated by the different DateRecorded entries.

I'd like to see a simple sum for the FirstDay.

Thanks for help, much appreciated!
0
Gustav BrockCIOCommented:
Yes, just exclude it from the grouping section
SELECT 
    qryBookingDayswithYear.CustomerID, 
    qryBookingDayswithYear.FirstDay, 
    Sum([Booking Details Extended].ExtendedPrice) AS SumOfExtendedPrice
FROM 
    qryBookingDayswithYear 
INNER JOIN 
    [Booking Details Extended] 
    ON qryBookingDayswithYear.CustomerID = [Booking Details Extended].CustomerID
GROUP BY 
    qryBookingDayswithYear.CustomerID, 
    qryBookingDayswithYear.FirstDay
HAVING
    qryBookingDayswithYear.FirstDay = Fix([Booking Details Extended].DateRecorded);

Open in new window

/gustav
0
cansevinAuthor Commented:
Thanks Gustav... unfortunately it comes up an error. See attached

Error-0414.pdf
0
Gustav BrockCIOCommented:
Yes, it should use WHERE now:
SELECT 
    qryBookingDayswithYear.CustomerID, 
    qryBookingDayswithYear.FirstDay, 
    Sum([Booking Details Extended].ExtendedPrice) AS SumOfExtendedPrice
FROM 
    qryBookingDayswithYear 
INNER JOIN 
    [Booking Details Extended] 
    ON qryBookingDayswithYear.CustomerID = [Booking Details Extended].CustomerID
WHERE
    qryBookingDayswithYear.FirstDay = Fix([Booking Details Extended].DateRecorded)
GROUP BY 
    qryBookingDayswithYear.CustomerID, 
    qryBookingDayswithYear.FirstDay;

Open in new window

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cansevinAuthor Commented:
Thanks! It worked... now I changed some things and have another problem. I'll post another question. I appreciate your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.