From 062517a6d4c6c56ea45add3d28f5844a2761c36e Mon Sep 17 00:00:00 2001 From: Scott Sutherland Date: Tue, 21 May 2024 08:43:17 -0500 Subject: [PATCH] Update pesterdb.sql Added stored procedure sp_WhoamiGtt that uses global temp tables. --- tests/pesterdb.sql | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/pesterdb.sql b/tests/pesterdb.sql index 9ebf28a..ccedab3 100644 --- a/tests/pesterdb.sql +++ b/tests/pesterdb.sql @@ -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