Question : failure to convert ???

I have a procedure that is running this calculation:

(((CONVERT(numeric(20,4),p.bidprice) * p.askQty) +(CONVERT(numeric(20,4),p.askPrice) * p.BidQty)) /
(CONVERT(decimal(12,5),p.bidqty) + CONVERT(decimal(12,5),p.askqty))) AS MicroPrice

I've recently done a lot of clean up to the data in the underlying tables (trades, orders, prices), and now i am trying to regenerate some statistics w/this procedure, but it's failing w/msg 8114
Error converting data type varchar to numberic

I have always used a where clause in there because of two values in askprice and bidprice that are
non-numeric .   i thought maybe there was something new in there causing this, but a check on isnumeric returns nothing but 'NaN', which i handle in my where.  here's a genericized version of the whole thing:

SELECT t.reason AS OrderType,t.TradeTime,t.Side,o.OrderDate,o.Message,o.Action,o.Price,
(((CONVERT(numeric(20,4),p.bidprice) * p.askQty) +(CONVERT(numeric(20,4),p.askPrice) * p.BidQty)) /
(CONVERT(decimal(12,5),p.bidqty) + CONVERT(decimal(12,5),p.askqty))) AS MicroPrice
FROM database.dbo.trades t RIGHT OUTER JOIN database.dbo.orders o
  ON t.tradetime = o.orderdate
  AND t.side = o.action RIGHT OUTER JOIN database.dbo.prices p
    ON t.tradetime = p.pricedate
    AND p.AskPrice <> 'NaN' AND p.BidPrice <> 'NaN'
OPTION (MAXDOP 1)

it has to be bidprice, askprice, bidqty or askqty causing this, and isnumeric check gives me nothing other than 'NaN' on the two price fields.  

does anybody know a good way to dig into this further and figure out what is causing the failure?

Answer : failure to convert ???

Ahhh well, it could have been worse - the title might have been "How to join", at least (I think) that "Failure to convert" has been well and truely answered.

where I would be going to from here (apart from the local bar)

1) create a view of the prices table with the converted values, and the microprice calculation without the NaN entries, and not 0 tradedqty
2) if sql 2005, index that view on datetime - need to read up on this because you are adding to the underlying datasets
3) create a new query joining trades and prices
4) try doing an inline query to get microprice

e.g. select trades.*, orders.*, (select top 1 microprices from vw_prices where pricesdate <= orderdate order by pricesdate desc) as microprice
from trades
inner join orders on trades.tradetime = orders.orderdate

the inline query is a bit of a killer - and can probably narrow it down to the day, but it is going to be tough to get the 'closest' any other way.

cheeres, have a drink on me, and maybe put this post to bed and start afresh with a new requirement...
Random Solutions  
 
programming4us programming4us