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
Try this:
Inspired from: http://www.sql-server-helper.com/tips/sort-ip-address.aspx
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:
Output:
If you don’t take that into consideration(as with the following query):
Those two queries will yield the same (incorrect) output:
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