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.
| Author |
Topic |
|
sqlalways
Starting Member
3 Posts |
Posted - 2007-04-17 : 23:40:40
|
| can we use variable name as table in the below queryactual syntaxselect * into table1 from table2but i want to use variable in place of table1which is a combination of valuesset @table1='abc'+@value and nowselect * into @table1 from table2error is incorrect syntax @table1plz help |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-04-17 : 23:49:21
|
| You would need to use dynamic SQL to accomplish that..set @table1='abc'+@value EXEC('select * into ' + @table1 + ' from table2')There's some pros and cons you would need to understand when it comes to dynamic SQL.Check out these articles to get a proper understanding.. http://www.sommarskog.se/dynamic_sql.html************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
|
|
|