function returns db name

  • I inherited 2 dozen scripts for data loading which have the source db name hardcoded in them. The db name changes every month. I want to create a function to store the db name as a string and call the function in each procedure.

    Is this the best way?

    How do I write that function?

    -K

  • May be you can store this db names in a separate table with code assigned to each table and if the update this table when your DB name is changing, living code the same, so you can retrieve name of Db by code in your d=function

  • I would recommend to make one file with all scripts and then do a search and replace otherwise you will have to convert all statements to string and Use EXECUTE Function.

  • Create FUNCTION dbo.fn_GetDbName ()

    RETURNS varchar(30)

    AS

    BEGIN

    RETURN 'dbName'

    END

    Then to use the function:

    declare @dbName as varchar(30)

    select @dbName=fn_GetDbName()

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply