Home Forums SQL Server 7,2000 T-SQL Dynamically change database depending on the server? RE: Dynamically change database depending on the server?

  • Just a shot in the dark but try an if exists option

    DECLARE @dbname nvarchar(128)

    SET @dbname = N'Production'

    IF (EXISTS (SELECT name

    FROM master.dbo.sysdatabases

    WHERE ('[' + name + ']' = @dbname

    OR name = @dbname)))