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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:57:45+00:00 2026-05-24T01:57:45+00:00

I need to find a way to get the data with the highest versionNumber.

  • 0

I need to find a way to get the data with the highest versionNumber.

Here is my database design:

VERSIONNUMBER - varchar(15)
DOWNLOADPATH - varchar(100)

Lets say I have records like:

VERSIONNUMBER -------- DOWNLOADPATH
1.1.2                  a.com
1.1.3                  b.com
2.1.4                  c.com
2.1.5                  d.com
2.2.1                  e.com

I need to get the record with the versionnumber 2.2.1. Need some help with the sql though 🙂

Thank you for any help

  • 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-24T01:57:46+00:00Added an answer on May 24, 2026 at 1:57 am

    Try this:

    with a as
    (
        select * from (values
        ('1.1.2'),('1.1.3'),('2.1.4 '), ('2.1.5'), ('2.2.1') ) as b(c)
    )
    select c, PARSENAME(c,1),PARSENAME(c,2), PARSENAME(c,3)
    from a
    order by 
    convert(int,PARSENAME(c,3)),
    convert(int,PARSENAME(c,2)),
    convert(int,PARSENAME(c,1))
    

    Inspired from: http://www.sql-server-helper.com/tips/sort-ip-address.aspx

    with a as
    (
        select * from (values
        ('1.1.2'),('1.1.3'),('2.1.4 '), ('2.1.5'), ('2.2.1') ) as b(c)
    ),
    x as 
    (
        select c, 
           convert(int,PARSENAME(c,3)) * 100 
           + convert(int,PARSENAME(c,2)) * 10 
           + convert(int,PARSENAME(c,1)) * 1 as the_value
        from a
    )
    select c from x where the_value = (select MAX(the_value) from x)
    

    In software development, it is typical to find a minor version number that has two digits in it, the version’s number don’t have any bearing with number’s value, thus version 1.12 is greater than 1.5; to compensate for that, you must pad the digits adequately:

        -- Use this, the query above is not future-proof :-)
    with a as
    (
        select * from (values
        ('2.1.4 '), ('2.1.12'), ('2.1.5'), ('2.2.1') ) as b(c)
    ),
    x as 
    (
        select c, 
           convert(int,PARSENAME(c,3)) * 100*100*100 
           + convert(int,PARSENAME(c,2)) * 100*100 
           + convert(int,PARSENAME(c,1)) * 100 as the_value
        from a
    )
    select c, the_value from x   
    order by the_value
    

    Output:

    2.1.4   2010400
    2.1.5   2010500
    2.1.12  2011200
    2.2.1   2020100
    

    If you don’t take that into consideration(as with the following query):

    with a as
    (
        select * from (values
        ('2.1.4 '), ('2.1.12'), ('2.1.5'), ('2.2.1') ) as b(c)
    ),
    x as 
    (
        select c, 
           convert(int,PARSENAME(c,3)) * 100
           + convert(int,PARSENAME(c,2)) * 10
           + convert(int,PARSENAME(c,1)) * 1 as the_value
        from a
    )
    select c, the_value from x   
    order by the_value;
    
    
        -- KorsG's answer has a bug too
    with a as
    (
        select * from (values
        ('2.1.4 '), ('2.1.12'), ('2.1.5'), ('2.2.1') ) as b(c)
    ),
    x as 
    (
        select c, 
           CAST(REPLACE(c, '.', '') AS int) as the_value
        from a
    )
    select c, the_value from x   
    order by the_value      
    

    Those two queries will yield the same (incorrect) output:

    c           the_value
    2.1.4   214
    2.1.5   215
    2.2.1   221
    2.1.12  222
    

    The 2.2.1 and 2.1.12’s value overlapped. That also happens when you merely remove the dots and directly convert the resulting string to int. 2.1.12 become two thousand one hundred twelve, 2.2.1 become two hundred twenty one. 2.2.1 is greater than 2.1.12, not less than

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

Sidebar

Related Questions

I need to find the best way to insert or update data in database
I need to find a way to get at the request/response streams inside of
I need to find a way to get the newly insert row, without previously
Possible Duplicate: I need a good way to get data from a thread to
I need to find a way to crawl one of our company's web applications
I need to find a way to hide HTML Rows (or Tables) from view
I need to find a way to monitor the status of a list of
I need to find a way to spin off a thread from a static
I need to find a way to call a vb.net function in my aspx
I need to find some way of displaying a drop-down menu that depending on

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.