Does a stored procedure know its own name?

  • I have some stored procedures that call another SP which sends out mails(SP_SendMail).

    I need the calling SPs to pass their own name to the SP_SendMail as a parameter.

    I don't want to hardcode each SP's name inside it. I want a common code, something like:

    declare @CallingSPName varchar(100)

    set @CallingSPName = @@MyName

    exec SP_SendMail @Body, @To, @From, @Subject, @CallingSPName

    Is there a way I can achieve this, without actually typing the name of the SP inside it?

  • select object_name(@@procid)

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537

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

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