SQL: how to predicate over stored procedure's result sets?

前端 未结 3 1564
耶瑟儿~
耶瑟儿~ 2021-01-24 00:54

Simple question I couldn\'t figure out (not a SQL expert... sorry): I want to do a select on the result set of sp_who2. How can I?

for ex. select SPID from [result set f

3条回答
  •  爱一瞬间的悲伤
    2021-01-24 01:50

    Use a loopback query like this

        SELECT SPID, Status, Login, HostName, BlkBy,DBName, 
       Command, CPUTime, DiskIO, LastBatch, ProgramName
            INTO #TempSpWho2
            FROM OPENROWSET ('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;',
          'set fmtonly off exec master.dbo.sp_who2')
    
        SELECT * FROM #TempSpWho2
    

    see also Store The Output Of A Stored Procedure In A Table Without Creating A Table

    on SQL Server 2005 and up use sys.dm_exec_sessions and sys.dm_exec_requests

提交回复
热议问题