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?
Asked
Active
Viewed 51 times
0
-
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 Answers
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
Sp_help returns more than one result sets. The following link might be helpful in that case:

sacse
- 3,634
- 2
- 15
- 24