starsky51
MIS
- Mar 11, 2002
- 91
I'm trying to write a stored procedure which can identify which database it has been called from. Using the following example:
if I call it from a different database:
it would print the string 'database1'.
What I would like is for the stored proc to identify which context the EXEC statement was in when it was run. (In this example, 'database2'.)
Any ideas?
Code:
USE database1
GO
CREATE PROC dbo.uspPrintDbName
AS
PRINT DB_NAME()
Code:
USE database2
GO
EXEC database1.dbo.uspPrintDbName
What I would like is for the stored proc to identify which context the EXEC statement was in when it was run. (In this example, 'database2'.)
Any ideas?