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 |
SKP
Starting Member
34 Posts |
Posted - 2006-08-15 : 07:14:48
|
Hi!, I have a table called TestTable with three columns Col_A,Col_B,Col_C .I need to alter this table, I have to drop all these three columns and create a new column called Col_D, this column will have its values as the name's of last three columns,Old Table looks like:Col_A,Col_B,Col_CNew Table should look like:Col_D-----Col_ACol_BCol_CCan any of you please help me on writting a T-Sql to achieve the desired goal?Thank you. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-15 : 07:19:46
|
[code]ALTER TABLE TestTableADD Col_D VARCHAR(50)INSERT TestTable ( Col_D )SELECT 'Col_A' UNION ALLSELECT 'Col_B' UNION ALLSELECT 'Col_C'ALTER TABLE TestTableDROP COLUMN Col_AALTER TABLE TestTableDROP COLUMN Col_BALTER TABLE TestTableDROP COLUMN Col_C[/code]Peter LarssonHelsingborg, Sweden |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-15 : 07:38:51
|
quote: Originally posted by SKP Hi!, I have a table called TestTable with three columns Col_A,Col_B,Col_C .I need to alter this table, I have to drop all these three columns and create a new column called Col_D, this column will have its values as the name's of last three columns,Old Table looks like:Col_A,Col_B,Col_CNew Table should look like:Col_D-----Col_ACol_BCol_CCan any of you please help me on writting a T-Sql to achieve the desired goal?Thank you.
What are you trying to do ? This is a bit unusual if I did not misunderstood you. KH |
 |
|
SKP
Starting Member
34 Posts |
Posted - 2006-08-15 : 08:51:29
|
Thanks Peter. |
 |
|
|
|
|
|
|