Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic schema name

Author  Topic 

companionz
Yak Posting Veteran

54 Posts

Posted - 2009-09-11 : 08:01:26
Hi Guys!

I've been trying to modify a procedure in which the dbschema name is hardcoded. I wanted to make it dynamic.
Can anyone help me in the same?

What i was trying is this:

I've a function which fetches this value

Declare @DbName VARCHAR(50)
SET @DbName = msdb.dbo.AI_GET_PARAMETER('VIP_DB','DBName')

Now, when i print this @DbName it gives me required value.

Issue arises when i do something like...

Select h.a1, c.a2
FROM @DbName.dbo.EventHeader h
JOIN @DbName.dbo.EventFV3CallData c
where h.b = c.b

Please suggest.

Thanks,
Sourav

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-11 : 08:24:59
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-13 : 13:56:18
why do you want to pass db name as a param value? does same tables exist on multiple dbs?
Go to Top of Page
   

- Advertisement -