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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:38:23+00:00 2026-05-25T06:38:23+00:00

I have a query that I use on a MySQL database that orders the

  • 0

I have a query that I use on a MySQL database that orders the result, casting a char database field to integer when possible (when the char string is numeric), so for example the ORDER BY clause that I use on MySQL is:

ORDER BY
   CASE 
   WHEN CONVERT(charfield, SIGNED INTEGER) IS NOT NULL THEN
        CAST(charfield AS SIGNED INTEGER)  
   ELSE 9999999999 END

Where charfield is a database field character(25).

How can I translate this ORDER BY clause for Firebird 2.5?

  • 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-25T06:38:24+00:00Added an answer on May 25, 2026 at 6:38 am

    You could use SIMILAR TO operator, ie

    ORDER BY
       CASE 
          WHEN charfield SIMILAR TO '[0-9]+' THEN CAST(charfield AS INTEGER) 
          ELSE 9999999 
       END
    

    If the field has leading or trailing spaces then you have to use TRIM() function to get rid of those before test, ie

    WHEN TRIM(charfield) SIMILAR TO ...
    

    And to allow negative numbers you have to modify the pattern to include -, ie the clause would became

    ORDER BY
       CASE 
          WHEN TRIM(charfield) SIMILAR TO '\-?[0-9]+' ESCAPE '\' THEN CAST(charfield AS INTEGER) 
          ELSE 9999999 
       END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query that I use to retrieve random rows from a
I have the next query that I run via SQLCMD.EXE use [AxDWH_Central_Reporting] GO EXEC
I have a Maketable query in an Access db that could use an Autonumber
Hi I have a really complicated dynamic query that i want to use to
I am using in C# MYsql .I have query that works if I run
I have a query that is dynamically built after looking up a field list
I have a script that polls a MySQL database (Nagios, specifically) for the date/time
I have a PHP script that inserts data into a mysql database. The table
I have two MySQL database tables that are meant to hold data for eshop
I have a field in a MySQL database called 'location' - it serves up

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.