sorting SQLite keys where no leading zeros at end of name

Peter Haworth pete at
Thu Jun 4 19:07:28 EDT 2015

If the text and numeric portions of the key are indeed separated by an
underscore, the following should work as an ORDER clause (untested).

ORDER BY substr(TheKeyColumn,1,instr(TheKeyColumn,'_')-1)
ASC,CAST(substr(TheKeyColumn,instr(theKeyColumn,'_')+1) AS INTEGER) ASC

If there are a fixed number of chars before the numeric part of the key,
then you can replace the instr calls with the appropriate number of chars.

lcSQL Software <>
Home of lcStackBrowser <> and
SQLiteAdmin <>

On Thu, Jun 4, 2015 at 3:36 PM, Dr. Hawkins <dochawk at> wrote:

> I have keys that get generated such as
>    someKey_1
>    someKey_2
> I just hit the snag that someKey_10 comes between the two of these.
> Is there a clean way to get SQLite (in memory) to ORDER these numerically
> without having to recode to force leading zeros?
> *yuk*
> --
> Dr. Richard E. Hawkins, Esq.
> (702) 508-8462
> _______________________________________________
> use-livecode mailing list
> use-livecode at
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:

More information about the Use-livecode mailing list