Print Page | Close Window

Data type mismatch in criteria expression

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=8019
Printed Date: 01 April 2026 at 1:12am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Data type mismatch in criteria expression
Posted By: ngaisteve1
Subject: Data type mismatch in criteria expression
Date Posted: 11 December 2003 at 9:45pm

I have these error mesg:

Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.

My code:

if strAlpha1 = "" then         &n bsp;         &n bsp;      
 sql = "Select * FROM customer, cust_businesstype WHERE companyname LIKE 'A%' "
 sql = sql & "OR companyname LIKE 'B%' "
 sql = sql & "AND businesstypeID = '10' "
 sql = sql & "AND companyID = custID "         ;           ;           ;           ;       
 sql = sql & "ORDER BY companyname"             
else         
  if strAlpha1 = "0" then
    sql = "Select * FROM customer, cust_businesstype WHERE ASC(LCASE(left(companyname,1))) not between 97 and 122 "
    sql = sql & "AND businesstypeID = '10' "
    sql = sql & "AND companyID = custID "           ;           ;           ;     
    sql = sql & "ORDER BY companyname"
  else       &n bsp;     
    sql = "Select * FROM customer, cust_businesstype WHERE companyname LIKE '" & strAlpha1 & "%' "
    sql = sql & "OR companyname LIKE '" & strAlpha2 & "%' "           ; 
    sql = sql & "AND businesstypeID = '10' "
    sql = sql & "AND companyID = custID "           ;              
    sql = sql & "ORDER BY companyname"
  end if
end if         &nbs p; 
rs.CursorLocation = 3
rs.open sql, conn

In my access db, custID in customer table is autonumber datatype, companyID in BusinessType table is number datatype.

Can anyone point out what's problem? When I took out the '' in '10' to become just 10, it says

The page cannot be displayed

The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.




Replies:
Posted By: aalavar
Date Posted: 12 December 2003 at 7:41am

I'm having a problem understanding what you are trying to do...

When selecting items from two tables, it's a lot easier to name the two tables so it's easier to read, it's also easier to help you out on.  i.e. is your query supposed to be like:

select * from customer c , cust_businesstype b
where b.companyname like 'A%' or b.companyname like 'B%'
and b.businesstypeid = 10
and b.companyid = c.custid
order by b.companyname

Also, what is the purpose of companyid = custid?

Sorry if these seem like dumb questions, but I can't figure out what you are trying to do from the code above... 



Posted By: ngaisteve1
Date Posted: 12 December 2003 at 7:45am
Basically, there are 3 tables. a join with b and b join with c.


Posted By: aalavar
Date Posted: 12 December 2003 at 10:21am

If there are three tables you are wanting to pull data from, you have to have them all listed in your select statement, i.e.

SELECT a.field, b.field FROM tablea a, tableb b, tablec c where c.field = a.field and b.field2=c.field2

Try adding the third table in your FROM clause and see what happens.  I wonder if your data mismatch is because it doesn't know what one of your variables is in the sql statement.



Posted By: MorningZ
Date Posted: 12 December 2003 at 12:09pm

well, all over the place you have

sql = sql & "AND businesstypeID = '10'

if "businesstypeID" is a numeric-based column, then comparing it to the string '10' will give you.....  you guessed it "Data Type Mismatch" since they don't indeed match



-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net