Datatype mismatch in criteria expression

Nati323

New Member
Joined
Feb 10, 2017
Messages
4
Hey I wrote this query:
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]SELECT[/COLOR][COLOR=#303336] dayar 
[/COLOR][COLOR=#101094]FROM[/COLOR][COLOR=#303336]   dayarim 
[/COLOR][COLOR=#101094]WHERE[/COLOR][COLOR=#303336]  [/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]enter_month[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Now[/COLOR][COLOR=#303336]())[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] 
    [/COLOR][COLOR=#101094]OR[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]enter_month[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]<[/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Now[/COLOR][COLOR=#303336]())[/COLOR][COLOR=#303336] 
         [/COLOR][COLOR=#101094]AND[/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]left_month[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]>=[/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Now[/COLOR][COLOR=#303336]())[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] 
       [/COLOR][COLOR=#101094]AND[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336] Datediff[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]'m'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] Iif[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]enter_month[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Now[/COLOR][COLOR=#303336]()),[/COLOR][COLOR=#303336] enter_month[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] 
                                 [/COLOR][COLOR=#7D2727]'1/1/'[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]+[/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Now[/COLOR][COLOR=#303336]())),[/COLOR][COLOR=#303336] Now[/COLOR][COLOR=#303336]())[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]*[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]50[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]<[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336] 
           Datediff[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]'m'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]'1/1/'[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]+[/COLOR][COLOR=#303336] Year[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Now[/COLOR][COLOR=#303336]()),[/COLOR][COLOR=#303336] Now[/COLOR][COLOR=#303336]())[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336]*[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]50[/COLOR][COLOR=#303336] [/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336] [/COLOR]</code>

And I get this error:
Datatype mismatch in criteria expression

My table structure:
3b1b3a4e948c3ebdd0054c8db4fc7516.png


My table content:

url]


I red that this error means that I try to compare some data type with another data type
but I dont understand where I do it
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I can't edit, but the correct query is:
Rich (BB code):
[FONT=&quot]SELECT[/FONT][FONT=&quot] [/FONT][FONT=&quot]dayar[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]FROM[/FONT][FONT=&quot]   [/FONT][FONT=&quot]dayarim[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]WHERE[/FONT][FONT=&quot]  [/FONT][FONT=&quot]([/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]enter_month[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT][FONT=&quot]=[/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]Now[/FONT][FONT=&quot]([/FONT][FONT=&quot])[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]        [/FONT][FONT=&quot]OR[/FONT][FONT=&quot] [/FONT][FONT=&quot]([/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]enter_month[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT][FONT=&quot]<[/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]Now[/FONT][FONT=&quot]([/FONT][FONT=&quot])[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]             [/FONT][FONT=&quot]AND[/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]left_month[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT][FONT=&quot]>=[/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]Now[/FONT][FONT=&quot]([/FONT][FONT=&quot])[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]           [/FONT][FONT=&quot]AND[/FONT][FONT=&quot] [/FONT][FONT=&quot]([/FONT][FONT=&quot]SELECT[/FONT][FONT=&quot] [/FONT][FONT=&quot]Sum[/FONT][FONT=&quot]([/FONT][FONT=&quot]payments[/FONT][FONT=&quot].[/FONT][FONT=&quot]sum[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]                [/FONT][FONT=&quot]FROM[/FONT][FONT=&quot]   [/FONT][FONT=&quot]payments[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]                [/FONT][FONT=&quot]WHERE[/FONT][FONT=&quot]  [/FONT][FONT=&quot]payments[/FONT][FONT=&quot].[/FONT][FONT=&quot]paymentdate[/FONT][FONT=&quot] [/FONT][FONT=&quot]>[/FONT][FONT=&quot] [/FONT][FONT=&quot]'1/1'[/FONT][FONT=&quot] [/FONT][FONT=&quot]+[/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]Now[/FONT][FONT=&quot]([/FONT][FONT=&quot])[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]                       [/FONT][FONT=&quot]AND[/FONT][FONT=&quot] [/FONT][FONT=&quot]paymentdate[/FONT][FONT=&quot] [/FONT][FONT=&quot]<=[/FONT][FONT=&quot] [/FONT][FONT=&quot]Now[/FONT][FONT=&quot]([/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT]
[FONT=&quot]                       [/FONT][FONT=&quot]AND[/FONT][FONT=&quot] [/FONT][FONT=&quot]payerid[/FONT][FONT=&quot] [/FONT][FONT=&quot]=[/FONT][FONT=&quot] [/FONT][FONT=&quot]dayarim[/FONT][FONT=&quot].[/FONT][FONT=&quot]id[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT][FONT=&quot]<[/FONT][FONT=&quot] [/FONT][FONT=&quot]([/FONT][FONT=&quot] [/FONT]
[FONT=&quot]               [/FONT][FONT=&quot]Datediff[/FONT][FONT=&quot]([/FONT][FONT=&quot]'m'[/FONT][FONT=&quot],[/FONT][FONT=&quot] [/FONT][FONT=&quot]'1/1/'[/FONT][FONT=&quot] [/FONT][FONT=&quot]+[/FONT][FONT=&quot] [/FONT][FONT=&quot]Year[/FONT][FONT=&quot]([/FONT][FONT=&quot]Now[/FONT][FONT=&quot]([/FONT][FONT=&quot])[/FONT][FONT=&quot])[/FONT][FONT=&quot],[/FONT][FONT=&quot] [/FONT][FONT=&quot]Now[/FONT][FONT=&quot]([/FONT][FONT=&quot])[/FONT][FONT=&quot])[/FONT][FONT=&quot] [/FONT][FONT=&quot]*[/FONT][FONT=&quot] [/FONT][FONT=&quot]50[/FONT][FONT=&quot] [/FONT][FONT=&quot])[/FONT][FONT=&quot];[/FONT][FONT=&quot] 
[/FONT]
 
Upvote 0
Welcome to the Board!

So, does this mean it has been resolved, or is it still a problem?

If it is still a problem, I suspect the issue is here with these caclulations:
Code:
[COLOR=red]'1/1'[/COLOR][COLOR=silver]+[/COLOR][COLOR=fuchsia][I]Year[/I][/COLOR][COLOR=maroon]([/COLOR][COLOR=#FF0080][B]Now[/B][/COLOR][COLOR=maroon]([/COLOR][COLOR=maroon])[/COLOR][COLOR=maroon])[/COLOR]
I would build the date like this:
Code:
DateSerial(Year(Now()),1,1)

I see two places where you would need to change that.
 
Last edited:
Upvote 0
You are welcome!

The issue was that the way you were trying to build your date builds a string, so you were trying to compare a date to a string (hence, your datatype mismatch).
 
Upvote 0
according to your image
left_month
is blank

yet you use that field in a calculation
AND Year(left_month)>=Year(Now()))

so that should fail
so I don't understand why its working now
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,207
Members
449,214
Latest member
mr_ordinaryboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top