May 1, 2006 at 12:24 pm
I'm having a major Monday brainfart today.
We've got a report that pulls data from one of two different databases (that are on the same server). My co-worker and I know which database we're in based on where we logged into - from a techie standpoint. However, our ordinary users wouldn't know for sure where they're logged in. I want to put the database name on the report, but I haven't been able to find anything in BOL to steer me the right direction.
Is there an @@ variable or some way for me to pull the database name in T-SQL?
Thanks in advance!
May 1, 2006 at 12:38 pm
This should work: select
DB_NAME(DB_ID())
May 1, 2006 at 12:42 pm
That did it! Thank you very much!
May 1, 2006 at 7:03 pm
select db_name() will do
May 2, 2006 at 7:59 am
You can also check for existing of database using following sql statement
SELECT NAME FROM SYSDATABASES WHERE NAME='databasename'
May 2, 2006 at 9:12 am
This last one wouldn't have helped me out, as I wouldn't know which databasename to send - I was trying to figure out which database I was in.
As it is, if I knew the name, why would I want to select it off of sysdatabases when I already knew it?
Thanks anyhow.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply