ken bohnenkamp
8th November 2002, 21:57
I would like to create an index in a table for a date in descending order. Is this possible?

NPRao
9th November 2002, 00:32
Ken,

I dont think you can create an index with the specification of ascending/descending order of a field.

But you can specify it within your code -

select zmmig100.*
from zmmig100
where zmmig100._compnr = MIGRATION.COMPANY
order by zmmig100._index1 desc
selectdo
.....
endselect


You should also check the available indexes by Session option too.

If this doesnt help you, can you please post more details about your requirements.

Please specify your BaaN version etc info in your profile.

evesely
11th November 2002, 16:11
NPRao is right about not being able to choose descending versus ascending for table indices. If you really need this capability (for session sorting as an example), you could add another field to your custom table to be the "negative" of the field in question and then use this as part of a new index. For example, suppose your table had a customer field and a priority field and you wanted to sort by priority in descending order followed by customer in ascending order. You could create a new field (e.g., negprio) that was equal to -1 * priority. Your new index would then be negprio, customer.

Of course, there are big red flags here. You would have to code your session(s) to make sure that whenever a change was made to the priority field, a corresponding change was made to negprio. Also, although this is easily done for numerics, it would be somewhat more complicated for strings.

Good luck.

NPRao
11th November 2002, 19:16
Ed, yes thats a good idea... it didnt occur to me. ;)

The example you mentioned with a -ve number does work with descending sequences but how about Ken's problem? Is there a work around ?

I think we also need to refer to Ken's other posts which seem to be related to this problem -

Query Extension (http://www.baanboard.com/baanboard/showthread.php?s=&postid=27903#post27903)

Selecting Records on a detail form (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=7564)

evesely
11th November 2002, 19:23
Since the date in 4c4 is a six-digit integer, we could just create a field as tcmcs.long and do the multiplication. I think it should work directly, but if not, you could always covert the date into a pure long and then multiply. I suppose another option might be to subtract the date value from 999999. Lot's of ways to skin the cat...

(If he is in Baan 5, I guess he would use a double and then multiply by -1)