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?
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()))
0
cansevinAuthor Commented:
Bummer... Still same problem.
0
Dale FyeCommented:
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

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dale FyeCommented:
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.
0
cansevinAuthor Commented:
Thanks dale... still says Data Type mismatch.
0
Rey Obrero (Capricorn1)Commented:
try this

HAVING Cdate(DateValue(Nz([qryBookingRevenueTotals].[DayRecorded],#1/1/1950#)))=Date()
0
cansevinAuthor Commented:
Still same
0
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
0
cansevinAuthor Commented:
Still mismatch.
0
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

0
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();
0
Rey Obrero (Capricorn1)Commented:
try this

Having [DayRecorded]=Format(date(),"mm-dd-yy")
0
cansevinAuthor Commented:
Ray... would that replace the entire "Having" line? or add to it?
0
Rey Obrero (Capricorn1)Commented:
replace the whole line
0
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
0
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.
0
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
0
cansevinAuthor Commented:
Gustav... still same data type mismatch.
0
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
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 Gustav!!!
0
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
0
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!
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.