[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference iosg::all-in-1_v30

Title:*OLD* ALL-IN-1 (tm) Support Conference
Notice:Closed - See Note 4331.l to move to IOSG::ALL-IN-1
Moderator:IOSG::PYE
Created:Thu Jan 30 1992
Last Modified:Tue Jan 23 1996
Last Successful Update:Fri Jun 06 1997
Number of topics:4343
Total number of notes:18308

2813.0. "Sort on multiple fields" by WOTVAX::64354::Doran (I like traffic lights) Mon Jun 07 1993 16:17

Quick question on sorting...

Will sorting on multiple fields ever be supported?

ie

BIND/SORT=".field1,.field2" *DDS to SUBSCRIBER .....

The reason I ask is that I have a customer who has a problem that was briefly 
touched on in note 1766. They want to see the results of a DDS search (via 
SMD) in alphabetical order. We can achieve the aplhabetical on surname 
(.SURNAME1) - no problem. The problem is that the search gives names back in 
the order they were entered into DDS - 

Smith Zorba
Smith Andy
Smith William
Smith Bert

It would be nice to sort the list so that it appears as:-

Smith Andy
Smith Bert
Smith William
Smith Zorba

Which looks better. This can almost be achieved by setting the sort key to be 
.GIVENNAME1 - but this falls over on multiple surnames (as you would 
expect...):-

Small Andy
Smith Andy
Smith Bert
Smith William
Small Zebedee
Smith Zorba

Sorting on multiple fields would achieve the desired effect - can we have 
it??? ;^)


Cheers,

Andy
T.RTitleUserPersonal
Name
DateLines
2813.1Suggested workaroundSCOTTC::MARSHALLSpitfire Drivers Do It ToplessTue Jun 08 1993 11:0722
The following age-old trick allows you to do multiple key sorts:

BIND/SORT=".least-significant-field" *phantom1 TO dataset
BIND/SORT=".most-significant-field" *phantom2 TO *phantom1

In your case, the first bind should sort on the given name, and the second bind
should sort on the surname.  You can extend it to sort on any number of fields,
as long as the sorts are done in order from least significant to most
significant field.  If the dataset is large and you only want part of it, a
WITH RSE clause on the first BIND will (should?) stop subsequent binds sorting
records you don't want, and thus improve performance.

I just tried it with PROFIL and it works fine, but SUBSCRIBER is a funny beast
so I make no guarantees!

Oh, one other point; this method relies on the sorting algorithm being stable
(ie the sort doesn't change the ordering of records with identical keys; fyi,
mergesort is stable, quicksort isn't...)  Unfortunately, the algorithm used by
BIND isn't stable, so it won't always give the right result, but it's better
than not doing anything!

Scott
2813.2Doesn't it already exist??IOSG::CHINNICKgone walkaboutTue Jun 08 1993 13:2618
    
    Correct me if I'm wrong, but I was under the distinct impression that
    this functionality was supported:
    
    BIND/SORT=".most .least" *phantom to dataset
    
    Of course, this will do a TRIM on each field so you may need to put in
    field lengths.

    Note also that the magic "@" operator also works:
    
    BIND/SORT="@'expression'" *phantom to dataset
    
    where expression can be another data-set reference. This allows a form
    of JOIN and PROJECTION operation because you can also use this in the
    WITH clause.
    
    Paul.
2813.3found itWOTVAX::DORANAConfuse-a-cat LtdTue Jun 08 1993 13:539
    Paul,
    
    I found that the BIND/SORT=".field1 .field2" works this morning - you
    beat me to it.
    
    I cant find this documented though - is it anywhere?
    
    Cheers
    Andy
2813.4WARNUT::RICESteve Rice @OLOThu Jun 10 1993 17:5012
    So "they" weren't happy with the mods I made (were it just sorts into
    Surname order). If this is the customer I think it is you could have a
    job for life - they'll come up with another request now, at least it'
    more money for DEC :-)
    
    .Steve.
    
    BTW. Due to "reprofiling", experienced specialist for hire, so....
    	 Any customers in the North UK looking for an experienced
    	 ALL-IN-1/VMS System Manager in the next three months point 
    	 them in my direction.