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 |
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2008-01-23 : 07:25:09
|
| Hi,i want to create table [products1] where column names of table are read from another table as values.example:create table products1(select names from tbl_products)I know it is a bit strange, but i would need such function or procedure.thank you |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-23 : 07:27:05
|
| [code]Select *into products1from tbl_products where 1=0[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-23 : 07:29:18
|
Select top 0 *into products1from tbl_products E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-23 : 07:34:50
|
| If you need data remove where condition or top 0or Script the table;rename the name;run it;copy the data to itMadhivananFailing to plan is Planning to fail |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2008-01-23 : 07:37:21
|
| hi,i'm sorry for being vague.tbl_products consist ofidnamedescriptionand i want values from tbl_products.name to be named as columns in new table products1hope this is better explained :) |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-23 : 07:38:14
|
| Also, above two methods won't copy constraints or indexes of the original table. So scripting the original table and changing table name is the best option.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-23 : 07:39:44
|
quote: Originally posted by slimt_slimt hi,i'm sorry for being vague.tbl_products consist ofidnamedescriptionand i want values from tbl_products.name to be named as columns in new table products1hope this is better explained :)
Did you follow my suggestion?MadhivananFailing to plan is Planning to fail |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-23 : 07:43:51
|
| What what will be the data type for each of the column? This is possible with only dynamic sql.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2008-01-23 : 07:47:51
|
| data type for all columns is "int".i was thinking of dynamic sql too. |
 |
|
|
|
|
|