>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--