INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Conditional parsing on sort clause

Conditional parsing on sort clause

(OP)
I have a two tables regarding my question.  Table 1, say INDEX, stores metadata on statements.  Table 2, say DEFINITION, defines what type of record is in INDEX.

There is a column in table INDEX where the metadata, say METADATA, is stored.  This column is a CHARACTER type.  I need to write a query that will sort table INDEX by the METADATA column and have some sort of logic to parse the sort to an INTEGER when the related column, say TYPE, in DEFINITION is equal to 'I'.


Example desired sort when METADATA is defined as an 'I' type by column TYPE in table DEFINITION:

  SELECT
    *
  FROM
    INDEX INDEX,
    DEFINITION DEFINITION
  WHERE
    DEFINITION.DEF_ID = INDEX.DEF_ID AND
    DEFINITION.DEF_ID = 1
  ORDER BY INTEGER(METADATA)

Example normal sort:

  SELECT
    *
  FROM
    INDEX INDEX,
    DEFINITION DEFINITION
  WHERE
    DEFINITION.DEF_ID = INDEX.DEF_ID AND
    DEFINITION.DEF_ID = 1
  ORDER BY METADATA


Is there a way to add in the integer parsing of METADATA based on a related record in a different table?  Would it be possible to inject the INTEGER( ) into the ORDER BY clause based on some sort of IF statement/logic?


(Note:  This is the way our tables are designed, please don't suggest modifying the design as that is not a viable solution.  Thank you.)

RE: Conditional parsing on sort clause

Can you please share your table information?

RE: Conditional parsing on sort clause

I use this syntax

CODE

select empno
     , sex
     , salary
     , case when sex  = 'F'
            then salary * -1
            else salary
       end as sort_col     
from   employee
order by sort_col
Nonsence example, but when you replace "sex = male/female" by some kind of "debit/credit" code it suddenly makes sence :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close