I have a multi-million row table with a varchar field. Some of the rows of the varchar are floating point numbers. There is no constraint on other fields that can completely isolate which rows are numbers and which are not. I want to create queries with an ORDER BY on the rows with the numeric value in the varchar field (ignoring non-numerics). I can't just simply call MyField::numeric because it pukes on the non-numeric rows.
I thought of two basic options:
(a) Use a regex to determine if the row is numeric.
(b) Catch the cast exception and return a null for all non-numeric values.
Speed is crucial. I tried option (a) and it is painfully slow. I created a stored procedure to use a regex to check the value before the cast. Non-numerics return as null. I created an index using that stored procedure. The regex is so expensive. But I'm wondering if catching an exception is even worth the effort.
Is there a simple way to have MyField::numeric return nulls for non-numeric data? Any suggestions to make this run faster?
Thanks