Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SELECT * FROM @var ???

Author  Topic 

pop0v
Starting Member

5 Posts

Posted - 2008-12-17 : 08:15:15
SELECT * FROM @var
Where @var is string containing the name of the table i want to use.
How can i do this ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 08:17:09
[code]EXEC( 'SELECT * FROM '+ @var)[/code]

but this is not a good approach
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-24 : 05:40:32
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -