I want to select the name of the Db on which I am running a query and PRINT it.
How can I achieve this in T-SQL?
something like:
DECLARE @ActualDbName VARCHAR(200)
SET @ActualDbName = -- SELECT ...
PRINT @ActualDbName
I want to select the name of the Db on which I am running a query and PRINT it.
How can I achieve this in T-SQL?
something like:
DECLARE @ActualDbName VARCHAR(200)
SET @ActualDbName = -- SELECT ...
PRINT @ActualDbName
Use the function DB_NAME().
So you would replace your -- SELECT -- with something like:
SELECT DB_NAME() AS [Current Database];
Specified here: http://technet.microsoft.com/en-us/library/ms189753.aspx