Is there any way within a stored procedure for it to reference its own name? Say I want it to print its own name, but without hard-coding the name in the stored procedure. Is there any cheater way to get the name or id from within the procedure itself without using the actual name to find the information?
Potential Conflicts with System-defined Functions and User-defined Functions. Stored procedures and user-defined functions can have the same names if they have different numbers of arguments or different data types for arguments.
A stored procedure can call itself up to the maximum nesting level of 32. This is referred to as recursion.
Expand Databases, expand the database in which the procedure belongs, and then expand Programmability. Expand Stored Procedures, right-click the procedure and then click View Dependencies. View the list of objects that depend on the procedure. View the list of objects on which the procedure depends.
Try:
SELECT OBJECT_NAME(@@PROCID)
@@PROCID returns the object ID of the current SQL module. OBJECT_NAME translates an object ID to its name. Both are available from at least version 7 to 2008 of SQL Server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With