tags:

views:

36

answers:

3

We have a change control environment where the developers give scripts to change control people to run. we have dev,qa, & production environments.

I want to conditionalize a couple segments to do some different things depending on what database the change control person is running my script.

If @dbname='dev'
then
begin
 --do some dev stuff
end
If @dbname='QA'
then
begin
 --do some qa stuff
end
If @dbname='Prod'
then
begin
 --do some production stuff
end

How do I get at what the current connected database is and fill @dbname?

+5  A: 

SELECT db_name() should do the trick.

daft
+4  A: 

Use the system function db_name()

Select db_Name()
John Hartsock
That was perfectly synched answering, wasn't it? :-)
daft
lol... yes it was. probably only about 1 sec apart
John Hartsock
+5  A: 

I think it's just like:

SELECT DB_NAME() AS DBName
ho1
I had to pick one answer and "ho" answered first. Thanks everyone though/
gjutras
Actually, I think I answered last rather than first...
ho1