Returning the name of the database

Friday 6 March 2015 @ 1:34 am

This week we have a clever trick that was shared by Larry McCulloch of Lares Research as part of a Linked in discussion. The question was how to have the report automatically show the database being read. Apparently someone had run a report in a training/testing database and it had gotten mixed up with reports coming from the live database. If Crystal knew which database it was reading it could flag reports that were coming from someplace other than ‘live’. Larry’s suggestion was to add the following SQL expression in SQL Server environments):


Then people suggested various was of doing the same thing in Oracle environments:

(SELECT ora_database_name FROM dual)

(SELECT sys_context ( 'userenv' , 'db_name' ) FROM dual )

(SELECT global_name FROM global_name )

I tested the SQL Server example but I don’t have an Oracle environment to test the others. If you try them or have some feedback, let me know.

update 3/25/2014 – I heard from an Oracle user that all three examples work.

update 10/12/2015 – in SQL Server you can also use:  ( SELECT DB_NAME()  )

Leave a Reply

Recrystallize Pro

Crystal Reports Server