我有一个192.168.1.1/32形式的CIDR,我需要能够将/ 29转换为255.255.255.0的传统子网表示法(我的子网可能有问题)。这需要在T-SQL(MS SQL)中完成,而且我也不太可能使用CLR或任何其他非标准的2008r2功能。
最终结果是我需要将192.168.1.1/32转换为192.168.1.1 255.255.255.0其中/ 32可以是任何有效的/ X
答案 0 :(得分:1)
也许我不理解这个问题,但为什么它很复杂?
select
case
when right(cidr,2) = '24' then mask = '255.255.255.0'
when right(cidr,2) = '25' then mask = '255.255.255.128'
when right(cidr,2) = '26' then mask = '255.255.255.192'
when right(cidr,2) = '27' then mask = '255.255.255.224'
when right(cidr,2) = '28' then mask = '255.255.255.240'
when right(cidr,2) = '29' then mask = '255.255.255.248'
when right(cidr,2) = '30' then mask = '255.255.255.252'
when right(cidr,2) = '31' then mask = '255.255.255.254'
end as mask
from atable
where patindex(cidr,'%/[0-9][0-9]') > 0