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 database name passing

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2011-06-06 : 22:51:00
Hi All,

I need to pass fully qualified format DB name to the select statement dynamically.How can we do this ?

I tried below but throwing an error.

Pls help.

declare @db varchar(10)
set @db='master'
select * from [@db].[dbo].[aa]
select @db



Thanks,
Gangadhara MS
SQL Developer and DBA

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-06 : 22:55:13
use Dynamic SQL


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -