Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 howto get the name of a sql-server database

Author  Topic 

lalbatros
Yak Posting Veteran

69 Posts

Posted - 2008-01-07 : 08:35:26
I would like to get the name of the current database in a TSQL procedure.
Is that possible?

thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-07 : 08:37:11
db_name()


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

lalbatros
Yak Posting Veteran

69 Posts

Posted - 2008-01-07 : 08:54:08
Thanks a lot.
Go to Top of Page

lalbatros
Yak Posting Veteran

69 Posts

Posted - 2008-01-07 : 10:23:48
khtan,

You gave me a good hope, but I could not finish the work.
Here is my procedure:

ALTER PROCEDURE zzzTestAdo AS
EXEC master.dbo.xp_cmdshell 'C:\TestAdo.exe';


I would like to pass the database name to the program "TestAdo" within this procedure.
I have no experience in TSQL and therefore, I could not modify the above procedure to get the result I want.
(something like EXEC master.dbo.xp_cmdshell 'C:\TestAdo.exe' dbname() doesn't work)

Could you help once more ?

Thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-07 : 10:25:24
[code]declare @cmd varchar(1000)
select @cmd = 'C:\TestAdo.exe ''' + db_name() + ''''

exec master.dbo.xp_cmdshell @cmd[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

lalbatros
Yak Posting Veteran

69 Posts

Posted - 2008-01-07 : 10:28:27
Wonderful, and incredibely fast answer!!!
Thanks
Go to Top of Page
   

- Advertisement -