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

  • Home
  • SEARCH
  • 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 8952431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:52:19+00:00 2026-06-15T13:52:19+00:00

I have a varchar column that I have datetime values and now string values.

  • 0

I have a varchar column that I have datetime values and now string values. I need to order by the datetime value and list all the string values at the bottom. I have the following for the datetime:

ORDER BY CAST(q2.[Due Date] AS DATETIME) 

But my results have the value “On Hold” throughout my results. I need the “On Hold” to be on the bottom of the list.

  • 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-15T13:52:20+00:00Added an answer on June 15, 2026 at 1:52 pm

    If the only non-date value is ‘On Hold’, then this should work in most SQL engines:

    order by (case when q2.[Due Date] = 'On Hold' then 0 else 1 end) desc,
             (case when q2.[Due Date] <> 'On Hold' then cast(q2.[Due Date] as datetime) end)
    

    I would recommend, though, that if you are storing dates as strings, then use the format ‘YYYY-MM-DD HH:MI:SS’. This will allow you to sort them without having to do a conversion.

    If they are in this format, you could use something like:

    order by (case when left([Due Date], 1) between '0' and '9' then 0 else 1 end),
             [Due Date]
    

    (Just ordering by [Due Date] would work in most cases, since numbers sort before letters. However, an arbitrary string could start with other non-alpha characters.)

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

Sidebar

Related Questions

I have column with varchar values like 022008 that I need to convert into
I have a varchar column that has data like this top<somenumber> so the word
I currently have a varchar(255) column that stores the path to a small image
I have a varchar(100) column in a table that contains a mix of integers
I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
I have a column in my SQL-2005 database that used to be a varchar(max)
I have a MySQL database , with a column that is date type DATETIME
I have a table that contains a Date column in varchar format. The date
I have tables with this type of datetime: 2010-09-16 00:32:41.960' CreatedDate column. I need

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.