Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using variables to represent table name
Message
De
07/12/2000 07:24:21
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00450290
Message ID:
00450296
Vues:
28
As you've probably found out, SQL Server does not allow a variable in place of the table in a query. You're going to have to use Dynamic SQL to make this work:

DECLARE @cmd varchar(1000)
SET @cmd = 'SELECT * FROM ' + @tablename
EXECUTE (@cmd)

Check out the Execute command in the BOL for more info.

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform