September 19, 2005 at 1:13 pm
I am sure this is simple, but I cant find the answer anywhere I have looked. So, I am either not looking for the right thing, or ???? Anyway, in a sproc, I would like to retrieve the name of the current database to which I am attached (i.e. the value I would place on the USE command).
SET @MyDBName = ???????
September 19, 2005 at 1:18 pm
SELECT DB_NAME()
Good Hunting!
AJ Ahrens
webmaster@kritter.net
September 19, 2005 at 1:22 pm
DOH!
Thank you 🙂
September 20, 2005 at 11:23 am
Be cautious of "niladic" functions (like db_name(), user_name(), object_name(), etc.) if they being used in a stored procedures. They are "context" specific. In other words some of these functions will return different values dependent on how they are executed. Some examples:
use master
go
exec sp_whatever
use another_db
go
exec master..sp_whatever
In your case db_name() should work the same no matter what the execution "context".
RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply