Create proc usp_getClient_infor
as
set nocount on
Declare @rc int
Declare @RowCount int
Select @rc=
Select @RowCount=
begin
create table #tspid(
spid int null
ecid int null
status nchar(
loginname nchar(
hostname nchar(
blk bit null
dbname nchar(
cmd nchar(
)
Create table #userip(
[id]int identity(
txt varchar(
)
Create table #result(
[id]int identity(
ClientIP varchar(
hostname nchar(
login_time datetime default(getdate())
)
insert into #tspid(spid
declare @cmdStr varchar(
@hostName nchar(
@userip varchar(
@sendstr varchar(
declare tspid cursor
for select distinct hostname from #tspid with (nolock) where spid>
for read only
open tspid
fetch next from tspid into @hostname
While @@FETCH_STATUS =
begin
select @cmdStr=
insert into #userip(txt) exec master
select @rowcount=count(id) from #userIP
if @RowCount=
begin
insert into #Result(ClientIP
end
if @RowCount>
begin
select @userip=substring(txt
from #userIP
where txt like
insert into #Result(ClientIP
end
select @rc=@@error
if @rc=
truncate table #userip
fetch next from tspid into @hostname
end
close tspid
deallocate tspid
select * from #result with(nolock)
drop table #tspid
drop table #userip
drop table #result
end
go
exec usp_getClient_infor
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22055.html