Mike Eghtebas
asked on
create table TSQL using..
Select COLUMN_NAME, Data_Type From tblMeta gives me something like:
COLUMN_NAME Data_Type CHARACTER_MAX_LENGTH
--------------------- --------------- -------------------------- ---------- -
FirstName varchar 25
LastName varchar 25
Address varchar 50
How can I make a table in a Proc with table name passed as its parameter to create a new table base on the above data?
COLUMN_NAME Data_Type CHARACTER_MAX_LENGTH
--------------------- --------------- --------------------------
FirstName varchar 25
LastName varchar 25
Address varchar 50
How can I make a table in a Proc with table name passed as its parameter to create a new table base on the above data?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>The sample date in table tblTestMeta is shown below. I need code to create tblTemp with the listed field names in tblTestMeta:
So if your requirement is 'make a copy of tblTestMeta as tblTemp with all columns and data, assuming no Identity columns, then just use * instead of defining the columns, and switch the table names around
So if your requirement is 'make a copy of tblTestMeta as tblTemp with all columns and data, assuming no Identity columns, then just use * instead of defining the columns, and switch the table names around
SELECT @sql = 'SELECT * INTO tblMeta FROM ' + @table_name
ASKER
I must have done terrible job in describing what I want. I have tblTestMeta based on which I want to create tblTest:
tblTestMeta
tblTest (showing column captions only, not populated yet.)
tblTestMeta
FieldName FieldProperty
CustomerID int
FirstName varchar(30)
LastName varchar(30)
Address varchar(50)
.
.
.
tblTest (showing column captions only, not populated yet.)
CustomerID FirstName LastName Address ...
So, you need to create table tblTemp, that contains the column names of tblTestMeta?
One column for all names, or with the same column name / data type?
In other words, give me the schema of tblTest.
One column for all names, or with the same column name / data type?
In other words, give me the schema of tblTest.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The Proc below runs okay. The sample date in table tblTestMeta is shown below. I need code to create tblTemp with the listed field names in tblTestMeta:
Open in new window
tblTestMeta:
Open in new window
At a later point, tblTestMeta will be created as temp table inside the proce whic will be discussed in a new post later on.