Here is another method using the PARSENAME function to split the elements when you have 4 or fewer elements.
-- Parse up to 4 '.' delimited elements and sort by numeric value of element
select
a1.x,
a1.y,
Part1 = convert(int,nullif(parsename(a1.y,4),'')),
Part2 = convert(int,nullif(parsename(a1.y,3),'')),
Part3 = convert(int,nullif(parsename(a1.y,2),'')),
Part4 = convert(int,nullif(parsename(a1.y,1),''))
from
(
select
a.x,
y =
case datalength(a.x)-datalength(replace(a.x,'.',''))
when 0 then a.x+'. . . '
when 1 then a.x+'. . '
when 2 then a.x+'. '
when 3 then a.x
else null end
from
(
select x = '10.12.14.44'union all
select x = '10.12.4.44'union all
select x = '1.20.3'union all
select x = '1.20.41'union all
select x = '1.12'union all
select x = '1.2'union all
select x = '1..3'union all
select x = '1..3.5'union all
select x = '5'union all
select x = '1'
) a
) a1
order by
Part1,
Part2,
Part3,
Part4
x y Part1 Part2 Part3 Part4
----------- ----------------- ----------- ----------- ----------- -----------
1 1. . . 1 NULL NULL NULL
1..3 1..3. 1 NULL 3 NULL
1..3.5 1..3.5 1 NULL 3 5
1.2 1.2. . 1 2 NULL NULL
1.12 1.12. . 1 12 NULL NULL
1.20.3 1.20.3. 1 20 3 NULL
1.20.41 1.20.41. 1 20 41 NULL
5 5. . . 5 NULL NULL NULL
10.12.4.44 10.12.4.44 10 12 4 44
10.12.14.44 10.12.14.44 10 12 14 44