Environment - SQL Server

SQL Code

The following SQL will return the environment (SQL Server Instance + Database Name) in which it runs; for example: [MyServer\MyInstance].[MyDatabase].

{copytext|div1}
select
     Environment    = '[' + convert(varchar(300), serverproperty('servername')) 
                                + '].[' + db_name() + ']'

Using in a Report

1. Create a new dataset in your report called Environment, which uses the same data source as your main dataset and is based on the above SQL statement.

Environment Dataset

Environment Dataset


2. Create a new report parameter called Environment. Make it hidden and set its default value to the Environment field in the Environment dataset.

Environment Report Parameter

Environment Report Parameter


3. Create a textbox in the page footer of your report (or wherever you like) and set its value to =Parameters!Environment.Value. Also, setting the font size to 6-point seems to be a good size.