Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using variables to represent table name
Message
From
07/12/2000 07:24:21
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00450290
Message ID:
00450296
Views:
27
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
Previous
Reply
Map
View

Click here to load this message in the networking platform