Data Type Mismatch Error on Open Recordset

masouder

Board Regular
Joined
Jul 5, 2013
Messages
111
Office Version
  1. 2013
Platform
  1. Windows
I am running SQL select queries against data in an Excel sheet. These queries have WHERE clauses. When I run a query with a WHERE clause on a numeric column I get a Data Type Mismatch error when the first record in the data set has a null value in the WHERE clause column.

For example, assume the following: SELECT @ FROM [Data$] WHERE [Year] = 2015. If the first record has a blank in the Year column then Excel returns the error. If I put any number in the first record in the Year column (e.g., 0) then the query runs fine.

Any ideas on how to avoid this error?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
maybe LIKE instead of =. Other think is is it really a number and not text
 
Upvote 0
Thank you. LIKE worked, but I am concerned about a situation where I may have a greater than or less than WHERE clause. Any ideas about that?

While I realize that Excel is not a database system, it still seems that I should not have to do something like this for the query to work properly.

Michael
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules. Be sure to follow & read the link at the end of the rule too!

Cross posted at: Data Type Mismatch Error on Open Recordset

If you do cross-post in the future and also provide a link, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,549
Members
449,170
Latest member
Gkiller

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