How can I do it?
select Host_name()
IP Address is trickier... It's possible you might be able to retrieve this
from the sysprocesses table. Or, perhaps write some VBScript code to
retrieve this information.
Steve
If you are just wanting to get the name, then you can use the host_name()
function in your original statement and there is no need for a trigger.
John
"AA" <a...@yahoo.com> wrote in message
news:03e301c2fd13$4977f740$a401...@phx.gbl...
create proc sp_get_hostip (@spid int = NULL)
as
set nocount on
declare @host varchar(100)
declare @ip varchar(15)
declare @cmd varchar(200)
declare @temp varchar(255)
create table #ip(iptext varchar(255))
If @spid is null select @host = host_name()
else
select @host = max(hostname)
from master..sysprocesses
where spid = @spid
if @host is not null
begin
set @cmd = 'ping -n 1 ' + @host
insert #ip exec master..xp_cmdshell @cmd
select @ip = ISNULL(substring(iptext,(charindex('[',iptext)+1),
(charindex(']',iptext)-(charindex('[',iptext)+1))),'')
from #ip
where charindex('[',iptext)>0
end
drop table #ip
select NULLIF(rtrim(@host),'') as 'Hostname',
rtrim(@ip) as 'IP_Address'
return
--
HTH
Jasper Smith (SQL Server MVP)
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"AA" <a...@yahoo.com> wrote in message
news:03e301c2fd13$4977f740$a401...@phx.gbl...