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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:45:45+00:00 2026-06-03T03:45:45+00:00

I have a MS SQL query that I am creating and I need to

  • 0

I have a MS SQL query that I am creating and I need to determine if a particular record falls into a “new” or “old” category based off of the version number.

There is a column ‘VersionNum’ and the old version is any version number from 2.75.99.99 and below while the new version is any version number from 2.76.00.00 and up. The data type for the column is varchar(20).

I was thinking about taking a subset of the string from X.XX and casting this as a decimal. Then once all versions are cast to a X.XX decimal I can determine old or new by performing a > or < in a case statement within the select.

Would this be the correct or idea way of going about deciding where the version numbers fall? Or is there some other method. I only ask because I would imagine that something similar to this is needed else where and this is not a unique situation.

EDIT: One additional issue. There are some versions that are not X.XX.XX.XX (2.76.00.00) and some are in the form: 8.00.00 and would be considered “Old” versions. This confuses the system a lot more than I once thought. I did get information that the 5 digit version (8.00.00) is considered old all the time. So whenever there are 5 digits, the version is old. So I am thinking I would perform a case statement similar to:

SELECT
    Old = CASE WHEN LEN(VersionNum) < 10 THEN 1
               WHEN CAST(SUBSTRING(VersionNum,1,4) AS DECIMAL(5,2)) < 1.52
                    AND LEN(VersionNum) >= 10 THEN 1
               ELSE 0
          END,
    New = CASE WHEN CAST(SUBSTRING(VersionNum,1,4) AS DECIMAL(5,3)) >= 1.52
                    AND LEN(VersionNum) >= 10 THEN 1
               ELSE 0
          END
FROM
    VersionTable

Is my logic correct? Or am I missing something. The inequality in the lengths is very annoying.

  • 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-03T03:45:46+00:00Added an answer on June 3, 2026 at 3:45 am

    You can always express such a “number” as an integer, assuming it will always have only 4 parts:

    DECLARE @x VARCHAR(20);
    
    SELECT @x = '2.76.99.99';
    
    SELECT 
     v = PARSENAME(@x, 4) * 1000000
       + PARSENAME(@x, 3) * 10000
       + PARSENAME(@x, 2) * 100
       + PARSENAME(@x, 1);
    

    Result:

    2769999
    

    So if you create a view or a computed column, you can compare using simple math instead of trying to do complicated parsing / conversion.

    EDIT based on comment

    If the table has some values that only have three octets, why not fix that?

    UPDATE dbo.table SET col = col + '.00'
      WHERE LEN(x) < 10;
    

    If you want to be more precise:

    UPDATE dbo.table SET col = LTRIM(RTRIM(col)) + '.00'
      WHERE LEN(LTRIM(RTRTIM(x))) - LEN(REPLACE(LTRIM(RTRIM(x)), '.', '')) = 3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a SQL query that returns a number of fields. I need
I need to be able to have an SQL query that searches my database
I have a SQL query that I'm trying to debug. It works fine for
I have an SQL query that returns all companies records ignore the ones with
I have a SQL query that I'm trying to write, but I'm not quite
i have a huge sql query that is attached to the rowsource of a
I have a complex sql query that I have in a stored procedure and
I have written a SQL query that works just fine, but am having a
I have an SQL query (below) that essentially takes a student from tbStudents, and
I have a custom SQL query that I run with this line: @avg_score =

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.