Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:52:27+00:00 2026-05-25T15:52:27+00:00

I have a load of rules about how a result set must be ordered.

  • 0

I have a load of rules about how a result set must be ordered. I need to use a CASE to work out the columns to order by.

I am trying this:

ORDER BY
              CASE 
                    WHEN ISNULL(actual_appearance_date, scheduled_appearance_date) IS NOT NULL AND icbm.emma_id IS NOT NULL -- We have it all!
                          THEN ISNULL(actual_appearance_date, scheduled_appearance_date) DESC , icbm.emma_id , version_number , icaci_t.[ijis_court_appearance_court_item_tracker_id]
                    WHEN ISNULL(actual_appearance_date, scheduled_appearance_date) IS NOT NULL AND icbm.emma_id IS NULL -- We have an appearance date, but it's manual.
                          THEN ISNULL(actual_appearance_date, scheduled_appearance_date) DESC, icaci_t.[ijis_court_appearance_court_item_tracker_id] DESC
                    WHEN ISNULL(actual_appearance_date, scheduled_appearance_date) IS NULL AND icbm.emma_id IS NOT NULL -- No appearance date, but it has a Business Message
                          THEN icbm.emma_id DESC, version_number DESC, icaci_t.[ijis_court_appearance_court_item_tracker_id] DESC
                    ELSE icaci_t.[ijis_court_appearance_court_item_tracker_id] DESC -- No Appearance date, not Message.
               END

But it seems I can only include one column after the THEN. But I need tio use a few columns, based on my rules.

Is there a way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:52:28+00:00Added an answer on May 25, 2026 at 3:52 pm

    To order a result set by diferent rules on different rows does not really make sense, as the conflicting rules will create inconsistencies in how individual orderings between rows are made. In other words there is no consistent ordering if the ordering rules are inconsistent.

    However I suspect you are making this issue much more complicated than it needs to be. I suspect you can just order by:

    ISNULL(actual_appearance_date, scheduled_appearance_date) DESC , icbm.emma_id , version_number , icaci_t.[ijis_court_appearance_court_item_tracker_id] 
    

    The NULL values will sort themselves out and be sorted together. Perhaps start from here and figure out what needs to change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have tried load and hebrew didn't work for me so i changed my
I have a load of tables all with the same 2 datetime columns (lastModDate,
Do you know any documentation about the rules of using update sites? I have
At my day job we have load balanced web servers which talk to load
I have to load huge (3000x3000) pictures in SWFLoader, and no problems with that
I have a load of php templates which uses a custom translate function __,
I have a load of signatures I wish to compare (all in ISF -
I have to load an array of doubles from a file, multiply each element
i have an UITableView in my app and i have to load some images
I develop a game that will have to load jpg images that now i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.