currently running stored procedure name

  • Is there anyway i can find out currently running stored procedure name ?

  • not sure what you mean...inside a TSQL code block, you could use

    print object_name(@@PROCID)

    or do you mean show me all the sql statements that are currently running on the server, like from one of the DMV's?

    SELECT DEST.TEXT

    FROM sys.[dm_exec_connections] SDEC

    CROSS APPLY sys.[dm_exec_sql_text](SDEC.[most_recent_sql_handle]) AS DEST

    --WHERE SDEC.[most_recent_session_id] = @spid

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Try this:

    SELECT r.*,t.text FROM sys.dm_exec_requests r cross apply sys.dm_exec_sql_text(r.sql_handle) t

    WHERE r.status IN (N'Suspended',N'Running',N'Runnable',N'Pending')

    The text column is the code of the procedure/batch that is currently running in SQL Server

    If all your SPs finish every quickly, the query may not be able to catch anything.

    You can try the following in a separate window then run the above query, you will catch it

    select * from master.dbo.spt_values

    WAITFOR DELAY N'00:30:00'

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply