Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable Database clause
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00762773
Message ID:
00762934
Vues:
10
you can't parameterize that portion of a query. you could use dynamic sql:

DECLARE @sql varchar(8000)
SET @sql = 'SELECT * FROM ' + @database + '..mytable'
EXECUTE (@sql)

What are you trying to do? Maybe there's a better way.

-Mike

>Can someone tell me how I might substitute the database name in a query that spans multiple databases with a variable so it can be passed to the stored procedure? EX.
>
>DECLARE @Database1 varchar(30)
>
>SET @Database = 'Database1'
>
>SELECT sf.filename
> FROM @Database..sysfiles sf
> INNER JOIN @Database..sysfiles1 sf1 ON sf.fileid = sf1.fileid
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform