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)+1, 0), 1),
CASE @stmt_end
WHEN -1
THEN DATALENGTH(s.TEXT)
ELSE
(@stmt_end - @stmt_start)
END
)
FROM ::fn_get_sql(@sql_handle) s
)
END
GO