[dba-SQLServer] Determine which database a sproc is being called from

Stoker, Kenneth E Kenneth.Stoker at pnl.gov
Fri Feb 13 18:24:55 CST 2004


Finally figured it out.  It was surprising to me that I couldn't find an
easier way.  If any of you know of a better way, I am all ears.

SELECT DISTINCT mdb.name
FROM sysfiles sf INNER JOIN master.dbo.sysaltfiles msf on sf.filename =
msf.filename 
	INNER JOIN master.dbo.sysdatabases mdb on msf.dbid = mdb.dbid

Have a good Valentine's Weekend everyone.

Ken Stoker
Technology Commercialization
Information Systems Administrator
PH: (509) 375-3758
FAX: (509) 375-6731
E-mail:  Kenneth.Stoker at pnl.gov 


-----Original Message-----
From: Stoker, Kenneth E 
Sent: Friday, February 13, 2004 3:05 PM
To: dba-SQLServer at databaseadvisors.com
Subject: [dba-SQLServer] Determine which database a sproc is being
called from


Is there a way for a sproc to determine which database it resides in
when called?  I would like to make a sproc I am build generic enough so
that it can be implemented in any database within a server instance.

Thanks for any help.

Ken Stoker
Technology Commercialization
Information Systems Administrator
PH: (509) 375-3758
FAX: (509) 375-6731
E-mail:  Kenneth.Stoker at pnl.gov 

_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com



More information about the dba-SQLServer mailing list