HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Execute sp_WhoIsActive as a query

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
queryexecutesp_whoisactive

Problem

I am at a client where they don't allow Adam Machanic's sp_WhoIsActive stored procedure to be installed anywhere on the SQL server. Does anyone have any suggestions for running it as a query instead?

Solution

In general you can run any SP as a query by getting rid of the "CREATE PROCEDURE" part and defining all of the parameters as variables.

For example

CREATE PROCEDURE test (@var1 int, @var2 int) AS
PRINT @var1
PRINT @var2


Would become

DECLARE @var1 int
DECLARE @var2 int
PRINT @var1
PRINT @var2


You might also ask them if it is ok if you create a "DBA" database for code like this and put the SP there. That way the SP is on the instance and will run correctly, but is still segregated from the rest of their databases.

Code Snippets

CREATE PROCEDURE test (@var1 int, @var2 int) AS
PRINT @var1
PRINT @var2
DECLARE @var1 int
DECLARE @var2 int
PRINT @var1
PRINT @var2

Context

StackExchange Database Administrators Q#37027, answer score: 3

Revisions (0)

No revisions yet.