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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:57:44+00:00 2026-06-11T09:57:44+00:00

I need help in ordering my resultset of SQL Server 2005. My Query is

  • 0

I need help in ordering my resultset of SQL Server 2005. My Query is

Select RQuery from EPMaster where PName IN ('PFNAME','POName','PFSName');

The result shown is in order as stored in the table EPMaster

In the table EPMaster, the order for values of PName are:

PFName -> 1
PFSName -> 2
POName -> 3

1 being the topmost and 3 being lowest

I need the results in order of the passed parameters of the query made with IN. It means that the result should be in the form

PFName -> 1
POName -> 2
PFsName -> 3
  • 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-06-11T09:57:45+00:00Added an answer on June 11, 2026 at 9:57 am

    Select does not guarantee any sort of order unless you specify an order by clause.

    For your particular case, you can use something like:

    ... order by (case when PName = 'PFSName' then 'ZZZZZ' else PName end ) asc
    

    but you should be aware that this sort of query may be a performance killer.

    If your query is created dynamically, and you have no control over the order in which the possibilities are given, yet still want to dictate that the rows are in the same order, you may have to resort to building your query differently, such as with:

    select 1 as xyzzy, RQuery from EPMaster where PName = 'PFNAME'
    union all
    select 2 as xyzzy, RQuery from EPMaster where PName = 'POName'
    union all
    select 3 as xyzzy, RQuery from EPMaster where PName = 'PFSName'
    order by 1 asc
    

    If your code builds this query rather than the in vesrsion, you can guarantee that the rows will be returned in the order as specified, because of the xyzzy column you add (and sort by).

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

Sidebar

Related Questions

need help/guide for sql select query, I have 2 table stock and stock_history, in
Need help transfer sql to sequel: SQL: SELECT table_t.curr_id FROM table_t INNER JOIN table_c
Need help with a query that I wrote: I have three tables Company id
Need help writing a script downloads data from google insight using c# this is
Need help to convert code from asp control to input type to fetch file
need a little help with some sql. I am trying to get distinct frompersonid,
I need some help figuring out and SQL Statement. I know what I want
I have an existing SQL Server 2005 database that runs our accounting/inventory application. We
Need help, function getFamily() { FB.api('/me/family', function(response) { alert(JSON.stringify(response)); }); } With the above
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend

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.