{"id":88,"date":"2011-01-26T11:37:12","date_gmt":"2011-01-26T18:37:12","guid":{"rendered":"http:\/\/www.sqldbpros.com\/?p=88"},"modified":"2011-01-26T11:37:12","modified_gmt":"2011-01-26T18:37:12","slug":"sql-server-get-proc-name-from-within-proc","status":"publish","type":"post","link":"http:\/\/sqldbpros.com\/wordpress\/2011\/01\/sql-server-get-proc-name-from-within-proc\/","title":{"rendered":"SQL Server &#8211; Get Proc Name From Within Proc"},"content":{"rendered":"<p>Want to get the name of a SQL Server stored procedure from with the procedure itself? No problem! This quick T-SQL script is all you need.<\/p>\n<blockquote><p>SELECT OBJECT_NAME(@@PROCID)<\/p><\/blockquote>\n<p>Need the schema as well?<\/p>\n<blockquote><p>SELECT OBJECT_SCHEMA_NAME(@@PROCID), OBJECT_NAME(@@PROCID)<\/p><\/blockquote>\n<p>I've found this particularly helpful when logging stored procedure execution to an audit table.<\/p>\n<p>p.s. I think this goes without saying but if you need only the object id the following complicated query can be used:<\/p>\n<blockquote><p>SELECT @@PROCID<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use this system function and variable to get the name of a stored procedure from within the procedure itself. The Object Id can also be returned.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-scripts"],"_links":{"self":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/comments?post=88"}],"version-history":[{"count":1,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":89,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/88\/revisions\/89"}],"wp:attachment":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}