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 6968221
In Process

The Archive Base Latest Questions

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

I am at a loss of how to sort the data in the second

  • 0

I am at a loss of how to sort the data in the second select statement of the following union query.

The desired results would be:

C null null null null null
I xxxx xxxx xxxx 1    xxxx
I xxxx xxxx xxxx 1    xxxx
I xxxx xxxx xxxx null xxxx
I xxxx xxxx xxxx null xxxx

Here is the code:

select 'C' [Identifier]
,null [Acct/Invoice #]
,null [Check #/Pay Amount]
,null [Check Amount/Error Code]
,null [Error Flag]
,null [Trx Account #]
union all
select 'I' [Indentifer]
,final_inv_number [Invoice #]
,final_final_pay_amount [Pay Amount]
,final_trans_code [Error Code]
,case when final_is_reconciled = 1 then 1 end [Error Flag]
,case when final_parse_type = 'ERROR CREATED' or final_parse_type = 'PREV PD'
    then final_account_number else null end [Trx Account #]
from #final
where final_net_pay_amount <> 0
--order by [Error Flag] ?
  • 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-27T16:25:27+00:00Added an answer on May 27, 2026 at 4:25 pm

    You are sorting the entire result, not just the records from the second select.

    You can use the [Identifier] field to keep the records from the first select first:

    order by [Identifier], [Error Flag] desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting hair loss here trying to find the error in my merge sort
I'm at a loss and hoping to find help here. What I'm trying to
iam using leigeber's sorting javascript to sort my data on my page......i took the
I'm at a loss here. I have a fairly simple thing going but seem
I'm at a bit of a loss here. I have a one-to-many relationship between
I am trying to sort data imported from a csv file. The data comes
I'm at a loss, I need some help. The string looks like: Hello World
I am at a loss how best to approach for loops in JavaScript. Hopefully
I'm at loss of how to create a Java enum in Clojure. I want
I'm at a loss, I can't see the reason something as simple as this

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.