Declare @IP varchar(20) Select @IP = '239.147.8.165' select @IP AS IP, cast(substring(@IP, 1, charindex('.', @IP) - 1) as int) AS Octet1, cast(substring(@IP, charindex('.', @IP) + 1, charindex('.', @IP, charindex('.', @IP) + 1) - charindex('.', @IP) - 1) as int) as Octet2, cast(reverse(substring(reverse(@IP), charindex('.', reverse(@IP)) + 1, charindex('.', reverse(@IP), charindex('.', reverse(@IP)) + 1) - charindex('.', reverse(@IP)) - 1)) as int) AS Octet3, cast(reverse(substring(reverse(@IP), 1, charindex('.', reverse(@IP)) - 1)) as int) as Octet4 |