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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:44:52+00:00 2026-06-06T22:44:52+00:00

Possible Duplicate: Case Order by using Null I’m looking to get a list of

  • 0

Possible Duplicate:
Case Order by using Null

I’m looking to get a list of records ordered by an “ordernum” field. The ordernum field is an int field. This field starts as NULL until set by a user. I would like the NULL entries to appear at the end of the list.

I am building a query as follows:

select *, case when (ordernum is null) then [largestInt] else ordernum end as newordernum
from tableName
order by newordernum

I know I could enter the value for the largest possible int for [largestInt], but I would like to replace [largestInt] with a variable. Is this possible?

  • 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-06T22:44:53+00:00Added an answer on June 6, 2026 at 10:44 pm

    I found a way to order NULL values on the bottom.

    http://sqlblog.com/blogs/denis_gobo/archive/2007/10/19/3048.aspx

    It meets my needs quite nicely. My query is now:

    select *
    from tableName
    order by case when ordernum is null then 1 else 0 end, ordernum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Will new return NULL in any case? Say i have a class
Possible Duplicate: Does readdir() guarantee an order? I'm guessing this isn't the case, and
Possible Duplicate: Using Case/Switch and GetType to determine the object If I hope to
Possible Duplicate: Is there an alternative to string.Replace that is case-insensitive? I'm looking for
Possible Duplicate: TSQL- Using CASE in WHERE clause with a < or = sign
Possible Duplicate: Business Case for Resharper I've just recently graduated and I'm working for
Possible Duplicate: How do I do a case insensitive string comparison in Python? I
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Switch Case on type of object (C#) I have a method signature

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.