0

I am new to SQL SERVER. And I am wondering can the system stored procedures (e.g., sp_help) can be called with query language such as select and where?

Kay
  • 175
  • 9
  • Nope, you can't. – Nayanish Damania Mar 07 '20 at 07:00
  • You have the short answer. The longer answer is that you cannot reference a stored procedure directly in a SELECT statement. That applies to any stored procedure - those that are system and supplied by MS and those that you write. – SMor Mar 07 '20 at 12:57

1 Answers1

0

you can store the results in a table and then filter out the records:

e.g.

DECLARE @Table TABLE(
        SPID INT,
        Status VARCHAR(MAX),
        LOGIN VARCHAR(MAX),
        HostName VARCHAR(MAX),
        BlkBy VARCHAR(MAX),
        DBName VARCHAR(MAX),
        Command VARCHAR(MAX),
        CPUTime INT,
        DiskIO INT,
        LastBatch VARCHAR(MAX),
        ProgramName VARCHAR(MAX),
        SPID_1 INT,
        REQUESTID INT
)

INSERT INTO @Table EXEC sp_who2

SELECT  *
FROM    @Table

Reference

Sp_help returns more than one result sets. The following link might be helpful in that case:

Store multiple result sets

Retrieve a single result set

sacse
  • 3,634
  • 2
  • 15
  • 24