Data Type Mismatch

I have a querry that is coming up a Data Type Mismatch in criteria expression. I would like it to sum only the value from TODAY. Any idea why it isnt' working? Thanks!

SELECT Sum(qryBookingRevenueTotals.SumofExtendedPrice) AS SumOfCountOfDAY, "ADAY" AS DateSpec
FROM qryBookingRevenueTotals
GROUP BY "ADAY", DateValue(Nz([qryBookingRevenueTotals].[DayRecorded],#1/1/1950#))
HAVING (((DateValue(Nz([qryBookingRevenueTotals].[DayRecorded],#1/1/1950#)))=DateValue(Now())));

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.

Rey Obrero (Capricorn1)Commented:
try just using Date() Instead of Now()


HAVING (((DateValue(Nz([qryBookingRevenueTotals].[DayRecorded],#1/1/1950#)))=Date()))
cansevinAuthor Commented:
Bummer... Still same problem.
Dale FyeOwner, Developing Solutions LLCCommented:
Personally, if you only want the data from today, then I would use a WHERE clause rather than a HAVING clause.  The WHERE clause will filter the data before doing the summation.  The HAVING clause will do the GroupBy first and compute the sums for all of the different dates, and then filter the results, which will probably take longer to run.

SELECT Sum(qryBookingRevenueTotals.SumofExtendedPrice) AS SumOfCountOfDAY
, "ADAY" AS DateSpec
FROM qryBookingRevenueTotals
WHERE DateValue(Nz([qryBookingRevenueTotals].[DayRecorded],#1/1/1950#))=Date()
GROUP BY "ADAY"
, DateValue(Nz([qryBookingRevenueTotals].[DayRecorded],#1/1/1950#))

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dale FyeOwner, Developing Solutions LLCCommented:
what does qryBookingRevenueTotals look like?  My guess is that you are using a Format( ) function to convert the [DayRecorded] into a specific format in that query, which will change the columns data type to string.
cansevinAuthor Commented:
Thanks dale... still says Data Type mismatch.
Rey Obrero (Capricorn1)Commented:
try this

HAVING Cdate(DateValue(Nz([qryBookingRevenueTotals].[DayRecorded],#1/1/1950#)))=Date()
cansevinAuthor Commented:
Still same
Gustav BrockCIOCommented:
Sometimes Nz returns strings, so try:
SELECT 
    Sum(qryBookingRevenueTotals.SumofExtendedPrice) AS SumOfCountOfDAY, 
    "ADAY" AS DateSpec
FROM 
    qryBookingRevenueTotals
GROUP BY 
    DateValue(IIf([qryBookingRevenueTotals].[DayRecorded] Is Null, #1/1/1950#, [qryBookingRevenueTotals].[DayRecorded]))
HAVING 
    DateValue(IIf([qryBookingRevenueTotals].[DayRecorded] Is Null, #1/1/1950#, [qryBookingRevenueTotals].[DayRecorded])) = Date();

Open in new window

/gustav
cansevinAuthor Commented:
Still mismatch.
cansevinAuthor Commented:
Not sure if this helps... but the querry it is pulling the data from is below. You can see how the "DateRecorded" is formatted. Not sure if this has something to do with it. Thanks.... really appreciate the help.

SELECT Format([Bookings.DateRecorded],"mm-dd-yy") AS DayRecorded, Sum([Booking Details Extended].ExtendedPrice) AS SumOfExtendedPrice
FROM (Bookings INNER JOIN qryWhosComputer ON Bookings.WhoBooked = qryWhosComputer.Last) INNER JOIN [Booking Details Extended] ON Bookings.BookNumber = [Booking Details Extended].BookNumber
WHERE (((Bookings.DateRecorded) Between #1/1/2015# And #12/31/2015#))
GROUP BY Format([Bookings.DateRecorded],"mm-dd-yy");

Open in new window

HainKurtSr. System AnalystCommented:
try filtering first, using isDate(...)

SELECT Sum(t.SumofExtendedPrice) AS SumOfCountOfDAY, "ADAY" AS DateSpec
FROM (select * from qryBookingRevenueTotals where isDate(DayRecorded)) as t
GROUP BY DateValue(IIf(t.[DayRecorded] Is Null, #1/1/1950#, t.[DayRecorded]))
HAVING DateValue(IIf(t.[DayRecorded] Is Null, #1/1/1950#, t.[DayRecorded])) = Date();
Rey Obrero (Capricorn1)Commented:
try this

Having [DayRecorded]=Format(date(),"mm-dd-yy")
cansevinAuthor Commented:
Ray... would that replace the entire "Having" line? or add to it?
Rey Obrero (Capricorn1)Commented:
replace the whole line
Gustav BrockCIOCommented:
That changes the whole picture. Use strings for Null values:
SELECT 
    Sum(qryBookingRevenueTotals.SumofExtendedPrice) AS SumOfCountOfDAY, 
    "ADAY" AS DateSpec
FROM 
    qryBookingRevenueTotals
GROUP BY 
    DateValue(IIf([qryBookingRevenueTotals].[DayRecorded] Is Null, '1/1/1950', [qryBookingRevenueTotals].[DayRecorded]))
HAVING 
    DateValue(IIf([qryBookingRevenueTotals].[DayRecorded] Is Null, '1/1/1950', [qryBookingRevenueTotals].[DayRecorded])) = Date();

Open in new window

/gustav
cansevinAuthor Commented:
Ray... no more data type mismatch. It now says:

You tried to execute a query that does not include the specified expression '[DayRecorded]=Format(date(),"mm-dd-yy")' as part of an aggregate function.
Rey Obrero (Capricorn1)Commented:
go in the design view of the query and select the Total row for that column to Expression or where or uncheck the box Show
cansevinAuthor Commented:
Gustav... still same data type mismatch.
Gustav BrockCIOCommented:
Then you may have invalid dates. So either change your source query to return the original date value, not the string.

Or use this:
SELECT 
    Sum(qryBookingRevenueTotals.SumofExtendedPrice) AS SumOfCountOfDAY, 
    "ADAY" AS DateSpec
FROM 
    qryBookingRevenueTotals
GROUP BY 
    DateValue(IIf(Not IsDate([qryBookingRevenueTotals].[DayRecorded]), '1/1/1950', [qryBookingRevenueTotals].[DayRecorded]))
HAVING 
    DateValue(IIf(Not IsDate([qryBookingRevenueTotals].[DayRecorded]), '1/1/1950', [qryBookingRevenueTotals].[DayRecorded])) = Date();

Open in new window

/gustav

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 Gustav!!!
Gustav BrockCIOCommented:
You are welcome!

What you have seen is the trouble arising when you start handling dates as strings. If not using Format, your original query would have worked with =Date(). If you feel, some records are missing with the last solution, try this.

/gustav
cansevinAuthor Commented:
Thanks Gustav... I posted another question regarding changing that query so it is for the current week. If you can help me out on that, i would greatly appreciate it. Thanks!
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.