Q:

How to change the db name dynamically using one db  storedprocedures to another db storedprocedures?

I am using one database like Test(db name) in this database i added 10 tables and 5 stored procedures , now i can call that procedures in another database like Test2(db name) ,
i am writing like this
Test database stored procedure is 

Create proc GetDetails()
As
select * from Emp;

after that storedprocedure using in another database like 
    Test2  database stored procedure is 

    Create proc GetDetails()
    As
Begin
    Exec Test..GetDetails()
End

Now client import the databases change the names as client wish now all stored procedures are not working in this situation how to solve the problem pls give me any suggestion , i can dynamically change the database name in all stored procedure.
Thanking u
Hemanth

A:

Assuming you can pass the target database name to the Test2 sproc (or read it from a configuration table or something), then you could use it like this:
-- assume @dbname has the name of the database where getdetails was created
declare @sql nvarchar(4000), @params nvarchar(4000), @dbname sysname
set @dbname = 'test'
set @sql = @dbname + '..getdetails'
set @params = ''
exec sp_executesql @sql, @params

