Home All Groups Group Topic Archive Search About
Author
31 Jan 2006 9:17 PM
Rick
Is there a way to sort by a text field but have it sort numerically.

I have an application that I have a text field but some record sets are only
numbers. As you know the "order by" does not sort them the way it would if
it was a numeric field is there any way around this?

    Thanks for any help!!!

Author
31 Jan 2006 9:27 PM
Grant
Depending on what you are using but you can try VAL() in SQL

Order by val(field_name)




Show quoteHide quote
"Rick" <r***@di-wave.com> wrote in message
news:uns24uqJGHA.3332@TK2MSFTNGP11.phx.gbl...
> Is there a way to sort by a text field but have it sort numerically.
>
> I have an application that I have a text field but some record sets are
> only numbers. As you know the "order by" does not sort them the way it
> would if it was a numeric field is there any way around this?
>
>    Thanks for any help!!!
>
Author
1 Feb 2006 5:46 AM
Hal Rosser
"Rick" <r***@di-wave.com> wrote in message
news:uns24uqJGHA.3332@TK2MSFTNGP11.phx.gbl...
> Is there a way to sort by a text field but have it sort numerically.
>
> I have an application that I have a text field but some record sets are
only
> numbers. As you know the "order by" does not sort them the way it would if
> it was a numeric field is there any way around this?
>
>     Thanks for any help!!!

Load it into an array as numbers using the val(str) function - and sort the
array.
But if Grant's solution works, I like his idea better.
Author
2 Feb 2006 5:40 PM
Rick
Thanks very much ALL this really helped!!!


Show quoteHide quote
"Rick" <r***@di-wave.com> wrote in message
news:uns24uqJGHA.3332@TK2MSFTNGP11.phx.gbl...
> Is there a way to sort by a text field but have it sort numerically.
>
> I have an application that I have a text field but some record sets are
> only numbers. As you know the "order by" does not sort them the way it
> would if it was a numeric field is there any way around this?
>
>    Thanks for any help!!!
>
Author
4 Feb 2006 3:14 AM
David Cox
"Rick" <r***@di-wave.com> wrote in message
news:uns24uqJGHA.3332@TK2MSFTNGP11.phx.gbl...
> Is there a way to sort by a text field but have it sort numerically.
>
> I have an application that I have a text field but some record sets are
> only numbers. As you know the "order by" does not sort them the way it
> would if it was a numeric field is there any way around this?
>
>    Thanks for any help!!!
>

Here is a solution that I think will sort data, whether the sort field
contains numbers or text:

SELECT * from tblBins order by IIf(IsNumeric(BinNum),0,BinNum),Val(BinNum)
ASC

The actual VB code is :

    SQL = "SELECT * from " & LkTable
    SQL = SQL & " order by "
    SQL = SQL & "IIf(IsNumeric(" & LkSortField & "),0,"
    SQL = SQL & LkSortField & "),"
    SQL = SQL & "Val(" & LkSortField & ")"
    SQL = SQL & " " & LkSortUpDown
    Set RS = DB.OpenRecordset(SQL)