I’m trying to create an SQL query that will order the results by a version number (e.g. 1.1, 4.5.10, etc.)
Here’s what I tried:
SELECT * FROM Requirements WHERE Requirements.Release NOT LIKE '%Obsolete%' ORDER BY Requirements.ReqNum
Now, the ReqNum field is a string field and unfortunately I can’t change it to a float or something like that because I have requirement numbers like 162.1.11.
When I get the results back, I’ll get ordering like this:
1.1 1.10 1.11 1.3
How can I write a query that will sort by lexicographic order?
… or,
How can I correctly sort the data?
Thanks for the input in advance!
For best results, refactor version number storage so that each section has it’s own column: MajorVersion, MinorVersion, Revision, Build. Then the ordering problem suddenly becomes trivial. You can also build a computed column for easy retrieval of the full string.