Page 1 of 1

Want to sort cursor on a table

PostPosted: Fri Oct 29, 2010 4:58 pm
by vegafacundodaniel
Hi,

A question please.

I have a cursor on a table and I'd want to sort it according to a criteria on a field. This criteria is not alphanumeric. It is a "special" criteria.

Example :
Field-A Field-B
-------- ----------
A 1
B 2
B 3
C 4
D 5
E 6

I'd want to sort that cursor with this criteria below :

Field-A Field-B
-------- -----------
B 2
B 3
D 5
A 1
C 4
E 6

i.e first records "B", second records "D", third records "A" and so on...

Thanks in advance !!!

Re: SORT

PostPosted: Fri Oct 29, 2010 5:03 pm
by enrico-sorichetti
any transformation must be capable of being described by an algorithm
otherwise it might be difficult/impossible to implement it in a programming language

describe the logic please ...
given a <key> what is the relation with the preceding and the subsequent keys

from the input and output You posted it is awkward to infer the algorithm

Re: SORT

PostPosted: Fri Oct 29, 2010 5:11 pm
by vegafacundodaniel
Sorry, but there is not a "logic criteria" to do it....

The criteria is what I am saying.

first records "B", second records "D", third records "A" and so on...

Thanks !!

Re: SORT

PostPosted: Fri Oct 29, 2010 5:16 pm
by enrico-sorichetti
we are just wasting time here :evil:

Re: SORT

PostPosted: Fri Oct 29, 2010 5:21 pm
by Robert Sample
Sorry, but there is not a "logic criteria" to do it....
If this is true, how do you "know" to put the B records first? Putting the B record first is a logic criterion -- and not one you have explained in any way.

Re: SORT

PostPosted: Fri Oct 29, 2010 11:39 pm
by dick scherrer
Hello,

You have started a topic about "SORT" in the COBOL part of the forum and then mention a cursor.

Suggest someone consider changing what the values represent so that they are more easily managed.

Or add another column that contains a "sequence code" that can be ordered by - a rather awful approach, but if the design cannot be corrected . . . :(

Re: Want to sort cursor on a table

PostPosted: Tue Nov 02, 2010 4:19 pm
by GuyC
somehow you'll have to document the required sequence in DB2.
This can be a code table with which you join
or a transformation you write in your sql.

select *
from tab1
order by
  case field-A
  when 'B' then 1
  when 'D' then 2
  when 'A' then 3
  when 'C' then 4
  when 'E' then 5
  else 99
  end