Current executing procedure name

前端 未结 5 1246
情歌与酒
情歌与酒 2020-12-23 15:57

Is it possible to get the name of the current Stored Procedure in MS SQL Server?

Maybe there is a system variable or function like GETDATE()?

5条回答
  •  感动是毒
    2020-12-23 16:13

    In the specific case where you are interested in the name of the currently executing temporary stored procedure, you can get it via:

    select name
    from tempdb.sys.procedures
    where object_id = @@procid
    

    You cannot use the accepted answer in SQL Server to find the name of the currently executing temporary stored procedure:

    create procedure #p
    as
    select object_name(@@PROCID) as name
    go
    exec #p
    
    
    name
    --------------------------------------------------------------------------------------------------------------------------------
    NULL
    
    (1 row affected)
    

提交回复
热议问题