T-SQL - fn_GetCurrentSQL

by John 2. April 2009 05:02

Here' my helper function which I put in my master_admin database.

 

CREATE  FUNCTION fn_GetCurrentSQL (
   
@sql_handle binary(20),
   
@stmt_start INT,
   
@stmt_end INT
)
RETURNS VARCHAR(8000)
AS
BEGIN
   RETURN 
(

   
SELECT 
       
SUBSTRING(s.TEXT,
           
COALESCE(NULLIF((@stmt_start/2)+10), 1),
           
CASE @stmt_end 
               
WHEN -
                   
THEN DATALENGTH(s.TEXT
               
ELSE 
                   
(@stmt_end @stmt_start
               
END
           

   
FROM    ::fn_get_sql(@sql_handles
)
END
GO

Tags:
Categories: SQL

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading