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 2000 Forums
 SQL Server Development (2000)
 Dynamically defining Table at runtime

Author  Topic 

tchinedu
Yak Posting Veteran

71 Posts

Posted - 2005-12-15 : 17:54:58
Please help guys,

I want to be able to create a variable table dynamically based on the rows in a reference table

I have a reference table containing rows I need to use for calculations with each row defining column names

eg: refTable
--- ColName-----ColText------------FieldType
=============================================
--LName ----- 'Last Name' -------- varchar
---FName ----- 'First Name' ------ varChar
---SSNum ----- 'Social Security' -- numeric
etc.

I want to be able to read the columns in this table and use them to
create a variable table in memory at runtime

ex. create @tablenew table
(
-- append the colName values here dynamically
-- so this var table columns is always reflecting the
-- columns in the reftable
)

Is this possible. I'm trying to avoid having to change the procedure
everytime a new field is added to the ref table

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-16 : 00:15:45
Why do you want to create table dynamically?
If you want to simulate the table structure, then

Select * into #tempTable from yourTable where 1=0
Insert into #tempTable select * from yourTable -- If you want to copy the rows

Madhivanan

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

- Advertisement -