× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Kent,

If you on an older version, you're have to specify the ORDER BY field
by ordinal number. In later version of the OS, you can (IIRC) specify
the case statement again. Honestly, I always use the ordinal, rather
than duplicate the case.

--by ordinal #
select fld1, fld2, fld3, fld4
case
when hinge = 'P' then 3
when height > 72 then 2
else 1
end as SortFld
from myTable
order by 5

--repeat case
select fld1, fld2, fld3, fld4
case
when hinge = 'P' then 3
when height > 72 then 2
else 1
end as SortFld
from myTable
order by case
when hinge = 'P' then 3
when height > 72 then 2
else 1
end

HTH,
Charles


On Tue, Jul 21, 2009 at 4:21 PM, Hohlen,
Kent<Kent.Hohlen@xxxxxxxxxxxxxxx> wrote:
Hello,

I'm trying to figure out a way to create a sort field that will have
different values based on the value of different fields in each record
retrieved by a SQL statement in a RPG program.  For example, if the
record returned has a "P" in the hinge field, I want this record to have
a sort value of 3.  Else if the height is greater then 72, then the sort
value should be a 2.  Else if the width is greater then 48, then the
sort value should also be a 2.  If none of these conditions are true,
then the sort field should have a value of 1.  Then I would like to use
the sort field in the ORDER BY clause.

I'm not having any luck figuring out how to create the condition syntax
and getting the sort field to work.

Any help is greatly appreciated.

Thanks,
Kent

--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.