|Subject||Re: [firebird-support] ORDER BY|
> Hi.Normally you can't.
> I have a VARCHAR field, name COD.
> If the column have only numeric
> vaues, i want to order this field like numeric value (1, 2,
> 3, ...10, 100), not like varchar (1, 10, 100, 2...)
> I don't know what values are in the field....varchar or numeric
> if they are only numerics i want to order by numeric values
> if they are numerics and varchar i want to order by varchar values
> How can i make that? An example please!!!!
A String is a string and an integer is an integer.
Quick and dirty you have the possibility to use two separate queries:
1. SELECT ... FROM ...
ORDER BY CAST ( COD AS INTEGER )
If this query returns an "conversion error on string" (when preparing /
opening it) you can be sure that you can't order by integer, so you have
to use the 2nd query:
2. SELECT ... FROM ...
ORDER BY COD
but in this case, the order will be 1, 100, 2, ...
Not so quick and dirty you can write a stored proc which does the
conversion and order by the output of the stored proc.
And maybe there's also some kind of StringToIntDef function somewhere in