Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable Substitution
Message
 
 
To
27/12/2000 19:26:26
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00457197
Message ID:
00457279
Views:
30
This message has been marked as the solution to the initial question of the thread.
>I want to write a select statement where I can use a variable to store the table name, then use that variable in my select statement. For example:
>
>Instead of:
> Select * from Mytable
>
>I want to:
>Set @SomeTableName = 'Mytable'
>Select * from @SomeTableName
>
>but, I can't get it to work. Can you tell me how I should approach this problem.


Greg,
Unfortunately you cannot get it work this way.
You have to use EXEC[UTE]

EXEC ( 'Select * from ' + @SomeTableName)

See BOL for details.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform