Quantcast
Channel: How to get the name of the database a stored procedure is executed in within that stored procedure while it's executing? - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 5

How to get the name of the database a stored procedure is executed in within that stored procedure while it's executing?

$
0
0

Weird question?...maybe, but I have a need. :)

I have a stored procedure that I want to use universally in any database.The stored procedure generates some dynamic SQL and then executes that SQL in a database that is passed in as one of the parameters in this procedure.

BUT I want to make the database parameter optional and when no database name is passed in, I want the dynamic SQL to execute within the same database that the procedure itself was called from. (Please keep in mind this procedure could be executed across databases and not within the same database that the procedure itself lives in.)


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images