T-SQL – fn_GetCurrentSQL

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

Comments are closed.

Post Navigation