One of the fields that I need displayed is called ProductValue. Depending on the restrains of the Product, the ProductValue can either be an integer or text. I want the resulting table to be ordered by value if it can be converted to integer, or alphabetically if it cannot. Currently I am have
Select *
from table t1
where table1.Product = 'box'
Order by cast(table1.ProductValue as int)
This query works fine, but when I change "box" to "paint"
it causes an error "Invalid Number".
with no restrains the table looks like
Product | ProductValue
-----------------------
box | 11111
box | 22222
paint | blue
paint | red
paint | green
Note: I am using Oracle.
The question is How can I order it by value if ProductValue can be converted to integer, or alphabetically if it cannot.
Select *
from table t1
where table1.Product = 'box'
Order by cast(table1.ProductValue as int)
This query works fine, but when I change "box" to "paint"
it causes an error "Invalid Number".
with no restrains the table looks like
Product | ProductValue
-----------------------
box | 11111
box | 22222
paint | blue
paint | red
paint | green
Note: I am using Oracle.
The question is How can I order it by value if ProductValue can be converted to integer, or alphabetically if it cannot.