If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Please Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-30-04, 12:37
gissa gissa is offline
Registered User
 
Join Date: Sep 2004
Posts: 37
Please Help

I am creating a query and am getting:
"Data Type Mismatch in criteria expression" error messages!!

It's driving me crazy. It only happens when I enter certain codes. For example, if I enter "2AP" the query works. If i enter "2AK", I receive the error!

Here is the SQL although I used Design View in Access to create the query:

SELECT TradeHist.[Portfolio Code], Sum([Trade Shares]*[Trade FX Rate]*[Order Decision Price]) AS MV, Sum([Trade Shares]*[Trade FX Rate]*[Order Decision Price]*[OrderHor])/[MV] AS OHMV, Sum(IIf([OrderHor]>=0.5,1,0)*[Trade Shares]*[Trade FX Rate]*[Order Decision Price])/[MV] AS PercOverFifty
FROM OrderHorizonQuery INNER JOIN TradeHist ON OrderHorizonQuery.[Order ID Master] = TradeHist.[Order ID Master]
GROUP BY TradeHist.[Portfolio Code]
HAVING (((TradeHist.[Portfolio Code])="2AK" Or (TradeHist.[Portfolio Code])="42O" Or (TradeHist.[Portfolio Code])="4UZ"));

Any help would be appreciated!
Reply With Quote
  #2 (permalink)  
Old 09-30-04, 15:01
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
put your conditions into the WHERE clause
Code:
select TradeHist.[Portfolio Code]
     , Sum([Trade Shares]*[Trade FX Rate]*[Order Decision Price]) AS MV
     , Sum([Trade Shares]*[Trade FX Rate]*[Order Decision Price]*[OrderHor])/[MV] AS OHMV
     , Sum(IIf([OrderHor]>=0.5 ,1 ,0)*[Trade Shares]*[Trade FX Rate]*[Order Decision Price])/[MV] AS PercOverFifty
  from OrderHorizonQuery 
inner 
  join TradeHist 
    on OrderHorizonQuery.[Order ID Master] 
     = TradeHist.[Order ID Master]
 where TradeHist.[Portfolio Code] in ('2AK','42O','4UZ')
group 
    by TradeHist.[Portfolio Code]
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-30-04, 16:42
gissa gissa is offline
Registered User
 
Join Date: Sep 2004
Posts: 37
Thanks for the effort but It is still yeilding the same error. any other ideas?
Reply With Quote
  #4 (permalink)  
Old 09-30-04, 16:51
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
double-check the datatypes of all columns involved
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-30-04, 22:53
gissa gissa is offline
Registered User
 
Join Date: Sep 2004
Posts: 37
How will I identify mistakes after looking at the data types of each column involved in the query? Thanks again for your continued support!

Reply With Quote
  #6 (permalink)  
Old 09-30-04, 23:30
roshanpm roshanpm is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
(((TradeHist.[Portfolio Code]='2AK') Or (TradeHist.[Portfolio Code]='42O') Or (TradeHist.[Portfolio Code])='4UZ'));

Try this
Reply With Quote
  #7 (permalink)  
Old 10-01-04, 00:06
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by gissa
How will I identify mistakes after looking at the data types of each column involved in the query? Thanks again for your continued support!

Based on your posted code, [OrderHor] should be a numeric type, and [Portfolio Code] should be a text type. I'd guess that one of them is of the wrong type.

-PatP
Reply With Quote
  #8 (permalink)  
Old 10-01-04, 06:49
gissa gissa is offline
Registered User
 
Join Date: Sep 2004
Posts: 37
Thanks all. Ill be at work in a bit. Ill let you know what I find!!!
Reply With Quote
  #9 (permalink)  
Old 10-01-04, 15:23
gissa gissa is offline
Registered User
 
Join Date: Sep 2004
Posts: 37
It worked!! Thanks
Reply With Quote
  #10 (permalink)  
Old 10-01-04, 15:34
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
mind telling us what worked?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 10-01-04, 16:17
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
yeah, I'm curious too. I can't seem to engage omniscient mode at the moment, so I'd like a wee bit more feedback.

-PatP
Reply With Quote
  #12 (permalink)  
Old 10-01-04, 16:25
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
heh

i always say something like "my crystal ball runs on Windows™ ME© and is down at the moment"
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On