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)
 Dynamic variable declaration POSSIBLE ?

Author  Topic 

daman
Yak Posting Veteran

72 Posts

Posted - 2007-11-28 : 12:32:51
I want to declare a bunch of temp tables @Temp1,@Temp2, etc
And I want to use a counter to add 1,2,3...to @Temp...is that Possible ?
Something like
DECLARE @Temp&@counter TABLE (ID int)

This is my not working example
DECLARE @counter INT
SET @counter = 0

WHILE @counter < 5

BEGIN
DECLARE @Temp&@counter TABLE (ID int)
SET @counter = @counter + 1
END

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-28 : 13:15:56
this seems like something you do not normally need to do. can you post the overall intent of what you are trying to accomplish, maybe you can avoid creating multiple table variables altogether :)
Go to Top of Page

daman
Yak Posting Veteran

72 Posts

Posted - 2007-11-28 : 14:15:02
My question is an extension of this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=91678

In that thread, @Table1,@Table2,.. will be replaced by a dynamic list of tables

Each of that table will have data filled in by different IDs.

select ID from indexlist where masterId = 1
ID
1
2
35
36
89
....
Go to Top of Page

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-28 : 14:57:02
how do you determine the names of the tables? how are the tables created and populated? before suggesting some really complex dynamic sql, maybe looking at how the process is starting it can be changed to make later reports/queries to be easier.
Go to Top of Page
   

- Advertisement -