troubleshooting Question

Capture executed SQL

Avatar of Larry Brister
Larry BristerFlag for United States of America asked on
* RDS 2019SQLMicrosoft SQL Server
2 Comments1 Solution21 ViewsLast Modified:
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
  (   'RefundCapture',       -- SQLProcedure - varchar(max)
      @CaptureExecSQL,       -- SQLCode - varchar(max)
      GETDATE() -- DateAdded - datetime
Database Analyst
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros