How Can I Sort A ‘Version Number’ Column Generically Using a SQL Server Query

If You are using SQL Server 2008

select VersionNo from Versions order by cast("https://stackoverflow.com/" + replace(VersionNo , '.', "https://stackoverflow.com/") + "https://stackoverflow.com/" as hierarchyid);

What is hierarchyid

Edit:

Solutions for 2000, 2005, 2008: Solutions to T-SQL Sorting Challenge here.

The challenge

Leave a Comment