declare @ip varchar(15),@sql varchar(1000)--得到ip地址 create table #ip(a varchar(200)) set @sql='ping '+host_name()+' -a -n 1 -l 1' insert into #ip exec master..xp_cmdshell @sqlselect @ip=left(a,patindex('%:%',a)-1) from( select a=substring(a,patindex('Ping statistics for %:%',a)+20,20) from #ip where a like 'Ping statistics for %:%') a--显示结果 select 用户计算机名=host_name(),ip地址=@ipdrop table #ip
create table #ip(a varchar(200))
set @sql='ping '+host_name()+' -a -n 1 -l 1'
insert into #ip exec master..xp_cmdshell @sqlselect @ip=left(a,patindex('%:%',a)-1) from(
select a=substring(a,patindex('Ping statistics for %:%',a)+20,20)
from #ip where a like 'Ping statistics for %:%') a--显示结果
select 用户计算机名=host_name(),ip地址=@ipdrop table #ip