Hello Forum Members/Gurus'
Background:
I have a IP range as: 1.2.3.0/255.255.255.0
I want the following output:
1.2.3.0
1.2.3.1
1.2.3.2
.
.
1.2.3.254
1.2.3.255
Proposed script by Patrick Hurst works like a charm.
CREATE TABLE test
(
ips VARCHAR(50)
)
INSERT INTO test
VALUES ('1.2.3.0/255.255.255.0'),
('12.13.14.15/255.255.255.0')
SELECT ips,
Parsename(LEFT(ips, Charindex('/', ips)), 4)
+ '.'
+ Parsename(LEFT(ips, Charindex('/', ips)), 3)
+ '.'
+ Parsename(LEFT(ips, Charindex('/', ips)), 2)
+ '.' + Cast(number AS VARCHAR(3)) as ip
FROM test
CROSS apply (SELECT[number]
FROM [master].[dbo].[spt_values]
WHERE type = 'P'
AND number > 0
AND NUmber <= 255) d(number)
However if the third value changes from 255 to 254 the range should be from 1.2.2.1 to 1.2.3.255.
1.2.3.0/255.255.255.0 1.2.3.1 to 1.2.3.255
1.2.3.0/255.255.254.0 1.2.2.1 to 1.2.3.255
1.2.3.0/255.255.252.0 1.2.0.1 to 1.2.3.255
Kind Regards,
Sqlquery9