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.
Author |
Topic |
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2010-10-13 : 15:40:08
|
I tried to pass database name by declared variable, getting the invalid object name error.Anybody know how to pass db name as varibaleDECLARE @DbName varchar(50)SET @DbName='MyDbName'Print @DbNameselect * from [@Dbname].dbo.tblName |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-10-13 : 15:42:18
|
Use dynamic SQL.CODO ERGO SUM |
 |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2010-10-13 : 15:45:04
|
i get dynamic value on @DbName, i used the CURSOR so it always get dynamic value. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-17 : 03:11:14
|
exec ('select * from '+[@Dbname]+'.dbo.tblName')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|