declare @i int,@j int,@a int,@b int,@c nvarchar(5)
set @i=1
set @j=102
set @a=1
set @b=254
while @i<=@j
begin
while @a<=@b
begin
if (len(@c)<10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'00'+'@c' from gongsia
else if (len(@c)<100 and @c>=10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'0'+'@c' from gongsia
else if (len(@c)>=100 )
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'@c' from gongsiaset @c=@c+1
set @a=@a+1
end
set @i=@i+1
end
set @i=1
set @j=102
set @a=1
set @b=254
while @i<=@j
begin
while @a<=@b
begin
if (len(@c)<10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'00'+'@c' from gongsia
else if (len(@c)<100 and @c>=10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'0'+'@c' from gongsia
else if (len(@c)>=100 )
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'@c' from gongsiaset @c=@c+1
set @a=@a+1
end
set @i=@i+1
end
set @i=1
set @j=102
set @a=1
set @b=254while @i<=@j
begin
while @a<=@b
begin
if (len(@c)<10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'00'+'@c' from gongsia
else if (len(@c)<100 and @c>=10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'0'+'@c' from gongsia
else if (len(@c)>=100 )
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'@c' from gongsia set @c=@c+1
set @a=@a+1
end
set @a=1
set @b=254
set @i=@i+1
end
set @i=1
set @j=102
set @a=1
set @b=254
while @i<=@j
begin
while @a<=@b
begin
if (len(@c)<10)
insert into gongsib(company,IpAddress) select company,left(ipaddress,12)+'00'+@c from gongsia
else if (len(@c)<100 and @c>=10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'0'+@c from gongsia
else if (len(@c)>=100 )
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+@c from gongsia set @c=@c+1
set @a=@a+1
end
set @i=@i+1
end
set @c=@c+1不过你:@c nvarchar(5)
其意义何在?
--@c定义为nvarchar(5),5个长度,太短了,但下面却判断 len(@c)<100,甚至还有@c>10,定义为255吧
set @i=1
set @j=102
set @a=1
set @b=254
while @i<=@j
begin
while @a<=@b
begin
if (len(@c)<10)
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'00'+'@c' from gongsia
else if (len(@c)<100 and @c>=10) ---@c>=10 不可以比较 可能是 len(@c)>=10
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'0'+'@c' from gongsia
else if (len(@c)>=100 )
insert into gongsib(company,IpAddress)
select company,left(ipaddress,12)+'@c' from gongsiaset @c=@c+1 --你看这里为什么 加一
set @a=@a+1
end
set @i=@i+1
end
declare @i int,@j int,@a int,@b int,@c nvarchar(5)
set @i=1
set @j=102
set @a=1
set @b=254
Set @C='11'
while @i<=@j
begin
select @i
while @a<=@b
begin
select len(@c),@a
if (len(@c)<10)
insert into gongsib(company,IpAddress) select company,left(ipaddress,12)+'00'+'@c' from gongsia
else if (len(@c)<100 and @c>=10)
insert into gongsib(company,IpAddress) select company,left(ipaddress,12)+'0'+'@c' from gongsia
else if (len(@c)>=100 )
insert into gongsib(company,IpAddress) select company,left(ipaddress,12)+'@c' from gongsia
set @c=@c+1
set @a=@a+1
end
set @i=@i+1
end
自己看看吧!
136.010.197.*
136.009.194.*
136.007.194.*
136.005.195.*
136.015.112.*
136.015.113.*
就是这么一组据,我只是想把*换成1-254插入到一张表里面,帮忙看看我的程序到底哪里出问题,
另外 from 表名后面我也加了where id=@i
这就是一个嵌套循环,各位,帮忙看看。因为ip是001,002,所以才用if语句判断
不如直接一个辅助表呢?
ip
1
2
...
254然后把那些IP和这个表直接cross join不就行了?