用proc获取ip地址
-- =============================================
-- Create procedure basic template
-- =============================================
-- creating the store procedure
IF EXISTS (SELECT name
FROM sysobjects
WHERE name = N'ccyt_getIp'
AND type = 'P')
DROP PROCEDURE ccyt_getIp
GO
CREATE PROCEDURE ccyt_getIp
@sname varchar(50)
AS
IF @sname='.'
BEGIN
SET @sname=@@SERVERNAME
END
IF @sname='local'
BEGIN
SET @sname=@@SERVERNAME
END
IF @sname like '%.%.%.%'
BEGIN
SELECT serverName=@sname,serverIP=@sname
END
ELSE
BEGIN
create table #ip(id int identity(1,1),re varchar(200))
declare @s varchar(1000)
set @s='ping '+ltrim(rtrim(@sname))+' -a -n 1 -l 1'
insert #ip(re) exec master..xp_cmdshell @s
select serverName=ltrim(rtrim(@sname)),serverIP=stuff(left(re,charindex(']',re)-1),1,charindex('[',re),'')
from #ip
where id=2
drop table #ip
END
GO