Skip to content

Commit

Permalink
Update pesterdb.sql
Browse files Browse the repository at this point in the history
Added stored procedure sp_WhoamiGtt that uses global temp tables.
  • Loading branch information
nullbind authored May 21, 2024
1 parent f08c50d commit 062517a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/pesterdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,36 @@ if exists (select name from sys.procedures where name = 'sp_findspy2')
GRANT EXECUTE ON sp_findspy2 to test_login_ownerchain
GO

-- Create stored procedures that executes OS commands using data from a global temp table

USE tempdb3;
GO

CREATE PROCEDURE sp_WhoamiGtt
AS
BEGIN
-- Create a global temporary table to store the command
IF OBJECT_ID('tempdb..##GlobalTempTableCommands') IS NULL
BEGIN
CREATE TABLE ##GlobalTempTableCommands (
Command NVARCHAR(4000)
);
END;

-- Insert the command "whoami" into the global temporary table
INSERT INTO ##GlobalTempTableCommands (Command)
VALUES ('whoami');

-- Declare a variable to hold the command
DECLARE @Command NVARCHAR(4000);

-- Select the command from the global temporary table
SELECT TOP 1 @Command = Command FROM ##GlobalTempTableCommands;

-- Execute the command using xp_cmdshell
EXEC xp_cmdshell @Command;
END;
GO

------------------------------------------------------------
-- Create Test Triggers
Expand Down

0 comments on commit 062517a

Please sign in to comment.