select 0 x into #tmp union all select 1 insert into #tmp select a.x * (select max(x) + 1 from #tmp) + b.x from #tmp a, #tmp b where a.x * (select max(x) + 1 from #tmp) + b.x not in (select x from #tmp) insert into #tmp select a.x * (select max(x) + 1 from #tmp) + b.x from #tmp a, #tmp b where a.x * (select max(x) + 1 from #tmp) + b.x not in (select x from #tmp) insert into #tmp select a.x * (select max(x) + 1 from #tmp) + b.x from #tmp a, #tmp b where a.x * (select max(x) + 1 from #tmp) + b.x not in (select x from #tmp) select convert(varchar, x) x, right('000' + convert(varchar, x), 3) s into #ips from #tmp --CLASS C network select a.x ip, a.s sort into #ip from #ips a where a.x not in (0,255) select '10.10.10.' + ip ip from #ip order by sort --CLASS B network: --select a.x + '.' + b.x ip, a.s + '.' + b.s sort into #ip from #ips a, #ips b where b.x not in (0,255) --select '10.10.' + ip ip from #ip order by sort --CLASS A network --select a.x + '.' + b.x + '.' + c.x ip, a.s + '.' + b.s + '.' + c.s sort into #ip from #ips a, #ips b, #ips c where c.x not in (0,255) --select '10.' + ip ip from #ip order by sort drop table #tmp drop table #ips drop table #ip