SQL Server 2008 以降:
select t.v
from (values ('1.1.1'), ('1.1.10'), ('1.1.11'), ('1.1.2'), ('1.1.3'), ('1.2.1'), ('10.1.1')) as t(v)
cross apply (
select x = cast('<i>' + replace(v, '.', '</i><i>') + '</i>' as xml)
) x
order by x.value('i[1]','int'),x.value('i[2]','int'), x.value('i[3]','int')
SQL Server 2005 以降:
;with t(v) as (
select '1.1.1' union all
select '1.1.10' union all
select '1.1.11' union all
select '1.1.2' union all
select '1.1.3' union all
select '1.2.1' union all
select '10.1.1'
)
select t.v
from t
cross apply (
select x = cast('<i>' + replace(v, '.', '</i><i>') + '</i>' as xml)
) x
order by x.value('i[1]','int'),x.value('i[2]','int'), x.value('i[3]','int')
出力:
v
------
1.1.1
1.1.2
1.1.3
1.1.10
1.1.11
1.2.1
10.1.1