Domanda

I need to extract data from an existing Padadox database under Delphi XE2 (yes, i more than 10 years divide them...).

i need to order the result depending on a field (id in the example) containing values such as : '1', '2 a', '100', '1 b', '50 bis'... and get this :

- 1
- 1 b
- 2 a
- 50 bis
- 100

maybe something like that could do it, but those keywords don't exist :

SELECT id, TRIM(TRIM(ALPHA FROM id)) as generated, TRIM(TRIM(NUMBER FROM id)) as generatedbis, etc
FROM "my.db"
WHERE ...
ORDER BY generated, generatedbis

how could i achieve such ordering with paradox... ?

È stato utile?

Soluzione

Try this:

SELECT id, CAST('0' + id AS INTEGER) A 
FROM "my.db" 
ORDER BY A, id

Altri suggerimenti

These ideas spring to mind:

  1. create a sort function in delphi that does the sort client-side, using a comparison/mapping function that rearranges the string into something that is compariable, maybe lexographically.

  2. add a column to the table whose data you wish to sort, that contains a modification of the values that can be compared with a standard string comparison and thus will work with ORDER BY

  3. add a stored function to paradox that does the modification of the values, and use this function in the ORDER BY clause.

by modification, I mean something like, separate the string into components, and re-join them with each component right-padded with enough spaces so that all of the components are in the same position in the string. This will only work reliably if you can say with confidence that for each of the components, no value will exceed a certain length in the database.

I am making these suggestions little/no knowledge of paradox or delphi, so you will have to take my suggestions with a grain of salt.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top