Avatar of Larry Brister
Larry Brister
Flag for United States of America asked on

Capture executed SQL

Is there a way to capture what was last executed on a stored procedure?

Other that this... I have a table I just insert what was passed in
But I don't want to do this on every proc
  SET @CaptureExecSQL = 'EXEC [dbo].[ewUpdatePaymentsbyPartialRefund_Capture] @InvoiceID = ''' + @InvoiceID + ''' , @AmountRefunded = ''' + CAST(@AmountRefunded AS NVARCHAR(300)) + ''' , @AmountRefundedActual = ''' + CAST(@AmountRefundedActual AS NVARCHAR(300)) + ''' , @UserID = ''' +  CAST(@UserID AS VARCHAR(50))  + ''''
  INSERT INTO dbo.ewSQLSearch
       (
           SQLProcedure,
           SQLCode,
           DateAdded
       )
  VALUES
  (   'RefundCapture',       -- SQLProcedure - varchar(max)
      @CaptureExecSQL,       -- SQLCode - varchar(max)
      GETDATE() -- DateAdded - datetime
      )

Open in new window

 
* RDS 2019SQLMicrosoft SQL Server

Avatar of undefined
Last Comment
lcohan

8/22/2022 - Mon
Jim Horn

<Knee-jerk reaction with total air code>  If that SP returns a set, you can create a temp table whose table definition EXACTLY matches that set, and then do an INSERT...

CREATE TABLE #tmp (goo int, foo int, boo int) 

INSERT INTO #tmp (goo, foo, boo) 
exec SPthatreturnscolumnsgoofooboo

-- Looky here
SELECT * FROM #tmp

Open in new window


ASKER CERTIFIED SOLUTION
lcohan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61