I want to loop through the records of the result set of sp_who.
Can this be done? How it can be done?
Regards,
Sevugan.C
code:
create table #tmpSpWho
(
spid smallint
,ecid smallint
,status nchar(30)
,loginame nchar(128)
,hostname nchar(128)
,blk char(5)
,dbname nchar(128)
,cmd nchar(16)
)
insert into #tmpSpWho
exec sp_who
HTH,
Cristian Lefter, SQL Server MVP
"Sevugan" <
Sevugan@.discussions.microsoft.com>
wrote in message
news:41413280-9A1A-481D-9FC8-31642E546811@.microsoft.com...
>
Hi,
>
I want to loop through the records of the result set of sp_who.
>
Can this be done? How it can be done?
>
>
Regards,
>
>
Sevugan.C|||You can create a temporary table to grab the result from the sp sp_who2.
Example:
use northwind
go
create table #t1 (
spid int,
status varchar(255),
login sysname,
hostname sysname,
blkby sysname,
dbname varchar(128),
command varchar(255),
cputime int,
diskio int,
lastbatch varchar(35),
programname varchar(128),
spid_1 int
)
go
insert into #t1
exec sp_who2
go
select
*
from
#t1
order by
login
go
drop table #t1
go
AMB
"Sevugan" wrote:
> Hi,
> I want to loop through the records of the result set of sp_who.
> Can this be done? How it can be done?
> Regards,
> Sevugan.C|||If you are wanting to do this on the client side, you can call sp_who into
an ADO recordset the same as any stored procedure.
"Sevugan" <Sevugan@.discussions.microsoft.com> wrote in message
news:41413280-9A1A-481D-9FC8-31642E546811@.microsoft.com...
> Hi,
> I want to loop through the records of the result set of sp_who.
> Can this be done? How it can be done?
> Regards,
> Sevugan.C|||Create TABLE #WHO
(
spid int,
ecid int,
Status Nvarchar(20),
LoginName Nvarchar(30),
Hostname Nvarchar(30),
blk int,
dbname Nvarchar(30),
cmd Nvarchar(255)
)
Insert #who
EXEC sp_who
Select * from #who
Create cursor to loop through data with whatever you want to do with the dat
a.
Hope this helps.
"Sevugan" wrote:
> Hi,
> I want to loop through the records of the result set of sp_who.
> Can this be done? How it can be done?
> Regards,
> Sevugan.C
No comments:
Post a Comment