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

前端 未结 4 510
天命终不由人
天命终不由人 2020-11-29 08:55

I wonder if the SQL geniuses amongst us could lend me a helping hand.

I have a column VersionNo in a table Versions that contains \'version

4条回答
  •  悲&欢浪女
    2020-11-29 09:04

    If You are using SQL Server 2008

    select VersionNo from Versions order by cast('/' + replace(VersionNo , '.', '/') + '/' as hierarchyid);
    

    What is hierarchyid

    Edit:

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

    The challenge

提交回复
热议问题