Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to specify second DB in SSMS
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
How to specify second DB in SSMS
Divers
Thread ID:
01683400
Message ID:
01683400
Vues:
47
Hi,

I am testing the SQL Select with a name of the database not current.
This case works:
use [FirstSQLDatabase]
go
select * from SecondSQLDatabase..mytable where 1=1
Now I want to put the 'SecondSQLDatabase' into a variable. Here is how I do it:
use [FirstSQLDatabase]
go 
declare @cSecondDb as Varchar(100)
set @cSecondDb = 'SecondSQLDatabase'
select * from @cSecondDb..mytable where 1=1    -- this is the line that causes the syntax error.
The above produces syntax error.

What am I missing?
TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform