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)
 Declare Variable

Author  Topic 

Christy
Starting Member

7 Posts

Posted - 2007-05-10 : 13:37:05
Can you declare a variable for the FROM?

Example:
=================
DECLARE @SrcTbl varchar(50)
set @SrcTbl = 'dbo.Test_31'

select col1, col2,col3
Into #tempTbl
From @SrcTbl

X002548
Not Just a Number

15586 Posts

Posted - 2007-05-10 : 13:40:56
You need to use dynamic sql..but why?

Plus the temp table would be out of scope



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Christy
Starting Member

7 Posts

Posted - 2007-05-10 : 13:49:32
I have a SQL script that needs to be ran for 31 different tables. the tables are identicial in structure, therefore I will run 1 script for all tables but I did not want to change the table name in 3 different places 31 times.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-11 : 06:05:06
www.sommarskog.se/dynamic_sql.html

Madhivanan

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

- Advertisement -