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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:35:10+00:00 2026-05-27T13:35:10+00:00

I have the following query in sql: SELECT a1 FROM dbo.myProductNames WHERE keycode =

  • 0

I have the following query in sql:

SELECT 
a1 
FROM 
dbo.myProductNames 
WHERE
 keycode = 40  OR keycode = 28 OR keycode = 32 OR keycode = 50

a1 = the name

I need the information in the table to output the names its queried in the order ive asked, so I need 40 to be first then 28 so on on.

The reason for this is my code reads the results and stores in an array that then is used to display on a form.

The table that the SQL query comes from has the information stored in num order, so 28 will be read first etc etc.

As I have said I need to get the information in the order I entered in the where clause.

I’m thinking something to do with nested Select statements although ive never tried nested selects.

Or, is there an easy way?

Any help would be great!

Many thanks in advance!


Update:

ok here is the solution thanks to you guys!

SqlCommand pgNameFill = new SqlCommand("SELECT  a1, CASE keycode WHEN @pg1 THEN 1 WHEN @pg2 THEN 2 WHEN @pg3 THEN 3 WHEN @pg4 THEN 4 END AS SortOrder FROM  dbo.myProductNames WHERE keycode IN (@pg1, @pg2, @pg3, @pg4) ORDER BY SortOrder ASC", conny1);
        
        pgNameFill.Parameters.AddWithValue("@pg1", pg1);
        pgNameFill.Parameters.AddWithValue("@pg2", pg2);
        pgNameFill.Parameters.AddWithValue("@pg3", pg3);
        pgNameFill.Parameters.AddWithValue("@pg4", pg4);
        SqlDataReader readpg = pgNameFill.ExecuteReader();

Many thanks for all the posts! I wish I could flag more answers than just one, oh well upvotes all around!

  • 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-27T13:35:11+00:00Added an answer on May 27, 2026 at 1:35 pm

    Add the following ORDER BY clause:

    ORDER BY
    CASE keycode 
        when 40 then 1
        when 28 then 2
        when 32 then 3
        when 50 then 4
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SQL query - SELECT * FROM dbo.LocalContacts WHERE name LIKE
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following SQL query: select AuditStatusId from dbo.ABC_AuditStatus where coalesce(AuditFrequency, 0) <>
I have the following SQL query select s.comments + s.further_comments from dbo.samples s where
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have the following which works in SQL Query Analyzer . select oh.* from
I have a following query (simplified): SELECT Id FROM dbo.Entity WHERE 1 = ALL
I have the following SQL SELECT CNumber, MAX(FormSubmitted), Score FROM dbo.vw_MSA WHERE (Score IS
I have the following SQL query: SELECT Comment, JD, Jurisdiction, RegStatus, Region, SPDR_NAME FROM
I have a SqlDependency set up using the following query: string sql = "SELECT

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.